Skip to content

Commit

Permalink
Handle BOM validation errors
Browse files Browse the repository at this point in the history
Instead of displaying a generic error message for all responses with status code >= 400, display a human-readable error description when RFC 9457 problem details are returned.

Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Mar 4, 2024
1 parent 9493cab commit 7dc5432
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
18 changes: 13 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,20 @@ export default {
}
this.axios.interceptors.response.use(null, (error) => {
// On error status codes (4xx - 5xx), display a toast with the HTTP status code and text.
// On error status codes (4xx - 5xx), display a toast with either:
// * The problem title and detail in case of an RFC 9457 response
// * the HTTP status code and text
if (error.response.status >= 400 && error.response.status < 500) {
this.$toastr.e(
error.response.statusText + ' (' + error.response.status + ')',
this.$t('condition.http_request_error'),
);
if (
error.response.headers['content-type'] === 'application/problem+json'
) {
this.$toastr.w(error.response.data.detail, error.response.data.title);
} else {
this.$toastr.e(
error.response.statusText + ' (' + error.response.status + ')',
this.$t('condition.http_request_error'),
);
}
} else {
this.$toastr.e(
error.response.statusText + ' (' + error.response.status + ')',
Expand Down
13 changes: 4 additions & 9 deletions src/views/portfolio/projects/ProjectUploadBomModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,10 @@ export default {
},
};
let url = `${this.$api.BASE_URL}/${this.$api.URL_BOM}`;
this.axios
.post(url, data, config)
.then((response) => {
this.$root.$emit('bv::hide::modal', 'projectUploadBomModal');
this.$toastr.s(this.$t('message.bom_uploaded'));
})
.catch((error) => {
this.$toastr.w(this.$t('condition.unsuccessful_action'));
});
this.axios.post(url, data, config).then(() => {
this.$root.$emit('bv::hide::modal', 'projectUploadBomModal');
this.$toastr.s(this.$t('message.bom_uploaded'));
});
},
},
};
Expand Down
13 changes: 4 additions & 9 deletions src/views/portfolio/projects/ProjectUploadVexModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,10 @@ export default {
},
};
let url = `${this.$api.BASE_URL}/${this.$api.URL_VEX}`;
this.axios
.post(url, data, config)
.then((response) => {
this.$root.$emit('bv::hide::modal', 'projectUploadVexModal');
this.$toastr.s(this.$t('message.vex_uploaded'));
})
.catch((error) => {
this.$toastr.w(this.$t('condition.unsuccessful_action'));
});
this.axios.post(url, data, config).then(() => {
this.$root.$emit('bv::hide::modal', 'projectUploadVexModal');
this.$toastr.s(this.$t('message.vex_uploaded'));
});
},
},
};
Expand Down

0 comments on commit 7dc5432

Please sign in to comment.