1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(feat) reporting ruby exceptions in the UI

This commit is contained in:
Sylvain 2023-04-05 09:47:38 +02:00
parent 5b14a9a4a7
commit bb717336e6
2 changed files with 6 additions and 2 deletions

View File

@ -2,6 +2,7 @@
- Italian language support (credits to https://crowdin.com/profile/olazzari)
- Improved error message on payzen misconfigured currency
- Improved reporting error messages in UI, from ruby exceptions
- Fix a bug: broken admin notifications if an order has been paid
- Fix a bug: unable to bulk update settings

View File

@ -27,19 +27,22 @@ client.interceptors.response.use(function (response) {
function extractHumanReadableMessage (error: string|Error): string {
if (typeof error === 'string') {
if (error.match(/^<!DOCTYPE html>/)) {
// parse ruby error pages
// parse ruby error pages (when an unhandled exception is raised)
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(error, 'text/html');
if (htmlDoc.querySelectorAll('h2').length > 2) {
return htmlDoc.querySelector('h2').textContent;
} else {
if (htmlDoc.querySelector('.exception-message .message')) {
return htmlDoc.querySelector('.exception-message .message').textContent;
}
return htmlDoc.querySelector('h1').textContent;
}
}
return error;
}
// parse Rails errors (as JSON) or API errors
// parse Rails errors (as JSON) or API errors (i.e. the API returns a JSON like {error: ...})
let message = '';
if (error instanceof Object) {
// API errors