Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1678db7
feat: centralize api error handling
didoda Mar 19, 2025
e1278ca
fix: processErrors
didoda Mar 20, 2025
a7c7dd0
refactor: js to vue
didoda Mar 25, 2025
30e6db8
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Mar 27, 2025
3bbee44
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Apr 8, 2025
fe59120
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Apr 18, 2025
d2f1035
refactor: use handleApiError
didoda Apr 18, 2025
922d0e9
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda May 6, 2025
4216100
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda May 16, 2025
1bf6190
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda May 20, 2025
0c9a7a4
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda May 27, 2025
41dc22e
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Jun 3, 2025
f51ed70
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Jun 13, 2025
76804ab
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Jun 17, 2025
dc678bd
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Jul 3, 2025
807b9be
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Jul 3, 2025
62343fb
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Jul 31, 2025
393c296
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Sep 15, 2025
6e94fa7
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Oct 9, 2025
c534930
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Oct 27, 2025
a5d0559
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Oct 27, 2025
1e9bebc
Merge branch 'master' into refactor/modal-error-on-api-calls
didoda Dec 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/js/app/components/dialog/dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</i>
</header>
<div
class="message mt-1 has-text-size-base"
class="message mt-1"
v-html="message"
v-if="message"
/>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/app/components/module/module-properties.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default {
});
}, 2000);
} catch (e) {
BEDITA.error(e);
this.$helpers.handleApiError(e);
} finally {
this.loading = false;
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/app/components/module/module-setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export default {
});
}, 2000);
} catch (e) {
BEDITA.error(e);
this.$helpers.handleApiError(e);
} finally {
this.loading = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,13 @@ export default {
const response = await fetch(`${BEDITA.base}/api/${this.objectType}/${this.objectId}`, options);
const responseJson = await response.json();
if (responseJson.error) {
BEDITA.error(responseJson.error);
this.$helpers.handleApiError(responseJson);
} else {
const captions = responseJson.data.attributes.captions || [];
this.reset(captions);
}
} catch (error) {
BEDITA.error(error);
this.$helpers.handleApiError(error);
} finally {
this.loading = false;
}
Expand Down
10 changes: 3 additions & 7 deletions resources/js/app/components/relation-view/relation-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ export default {
body: JSON.stringify({ data: toRemove }),
});
if (response?.error) {
BEDITA.error(response.error?.title || response?.error);
this.$helpers.handleApiError(response);
} else {
this.removedRelated = [];
this.prepareRelationsToRemove(this.removedRelated);
Expand All @@ -744,7 +744,7 @@ export default {
});
const json = await response.json();
if (json?.error) {
BEDITA.error(json.error?.title);
this.$helpers.handleApiError(json);
} else {
this.addedRelations = [];
this.modifiedRelations = [];
Expand All @@ -753,11 +753,7 @@ export default {
}
await this.reloadObjects();
} catch (error) {
if (typeof error === 'string') {
BEDITA.error(error);
} else {
BEDITA.error(error?.title);
}
this.$helpers.handleApiError(error);
} finally {
this.savingRelated = false;
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/app/components/relation-view/relations-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export default {
try {
const response = await fetch(postUrl, options);
const responseJson = await response.json();
if (responseJson.error) {
if (responseJson?.error) {
throw new Error(responseJson.error);
}

Expand Down
19 changes: 19 additions & 0 deletions resources/js/app/helpers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,25 @@ export default {

return response;
},

handleApiError(response) {
let message = '';
let detail = false;
if (typeof response === 'string') {
message = response;
} else if (response?.error && typeof response.error === 'string') {
message = response.error;
} else if (response?.message && typeof response.message === 'string') {
message = response.message;
} else {
if (response?.error?.status) {
message += `[${response.error.status}] `;
}
message += response?.error?.title || t`An error occurred`;
detail = response?.error?.detail || false;
}
BEDITA.error(message, document.body, detail);
},
}
}
};
4 changes: 2 additions & 2 deletions resources/js/app/pages/admin/appearance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export default {
const response = await fetch(`${BEDITA.base}/admin/appearance/save`, options);
const responseJson = await response.json();
if (responseJson.error) {
BEDITA.error(responseJson.error);
this.$helpers.handleApiError(responseJson);
}
} catch (error) {
BEDITA.error(error);
this.$helpers.handleApiError(error);
} finally {
this.loading = false;
this.loadingKey = '';
Expand Down
19 changes: 14 additions & 5 deletions resources/js/app/pages/modules/view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default {
}
if (json?.error) {
await this.showFlashMessages();
BEDITA.error(json.error);
this.$helpers.handleApiError(json);
throw new Error(json.error);
}

Expand Down Expand Up @@ -210,12 +210,21 @@ export default {
details = details + '\n' + e.details;
}
}
const message = t`OOOPS! Something went wrong` + '. ' + this.errors[0].message;
const title = t`OOOPS! Something went wrong` + '. ' + this.errors[0].message;
let params = {
error: {
title,
}
};
if (this.userRoles.includes('admin')) {
BEDITA.error(message, document.body, details);
} else {
BEDITA.error(message);
params = {
error: {
title,
details
}
}
}
this.$helpers.handleApiError(params);
this.errors = [];
},

Expand Down
Loading