From 40ef5b2d7ee22f32465c02a4c21b81cc6ac1f089 Mon Sep 17 00:00:00 2001 From: axolotle Date: Sun, 11 Apr 2021 14:39:41 +0200 Subject: [PATCH] try to format the error just before ApiError creation --- app/src/api/errors.js | 4 ++-- app/src/api/handlers.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/api/errors.js b/app/src/api/errors.js index cbca7c12..999aa2ca 100644 --- a/app/src/api/errors.js +++ b/app/src/api/errors.js @@ -7,8 +7,8 @@ import i18n from '@/i18n' class APIError extends Error { - constructor (request, { url, status, statusText }, errorData) { - super(errorData.error || i18n.t('error_server_unexpected')) + constructor (request, { url, status, statusText }, { error }) { + super(error ? error.replace('\n', '
') : i18n.t('error_server_unexpected')) const urlObj = new URL(url) this.name = 'APIError' this.code = status diff --git a/app/src/api/handlers.js b/app/src/api/handlers.js index 259e5d2d..123797da 100644 --- a/app/src/api/handlers.js +++ b/app/src/api/handlers.js @@ -59,7 +59,7 @@ export async function handleError (request, response, errorData) { let errorCode = response.status in errors ? response.status : undefined if (typeof errorData === 'string') { // FIXME API: Patching errors that are plain text or html. - errorData = { error: errorData.replace('\n', '
') } + errorData = { error: errorData } } if ('log_ref' in errorData) { // Define a special error so it won't get caught as a `APIBadRequestError`.