From bb717336e688e1f3aede7965e2e19b0e3f4dce6f Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 5 Apr 2023 09:47:38 +0200 Subject: [PATCH] (feat) reporting ruby exceptions in the UI --- CHANGELOG.md | 1 + app/frontend/src/javascript/api/clients/api-client.ts | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0e3129d0..70e609ffb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/frontend/src/javascript/api/clients/api-client.ts b/app/frontend/src/javascript/api/clients/api-client.ts index c8ddfc7b8..3c2c7dc6f 100644 --- a/app/frontend/src/javascript/api/clients/api-client.ts +++ b/app/frontend/src/javascript/api/clients/api-client.ts @@ -27,19 +27,22 @@ client.interceptors.response.use(function (response) { function extractHumanReadableMessage (error: string|Error): string { if (typeof error === 'string') { if (error.match(/^/)) { - // 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