try to format the error just before ApiError creation

This commit is contained in:
axolotle 2021-04-11 14:39:41 +02:00
parent 3f3fd2585f
commit 40ef5b2d7e
2 changed files with 3 additions and 3 deletions

View file

@ -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', '<br>') : i18n.t('error_server_unexpected'))
const urlObj = new URL(url)
this.name = 'APIError'
this.code = status

View file

@ -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', '<br>') }
errorData = { error: errorData }
}
if ('log_ref' in errorData) {
// Define a special error so it won't get caught as a `APIBadRequestError`.