Improve import error messages

This commit is contained in:
Jan-Niklas Weghorn 2023-11-10 13:28:20 +01:00
parent 8a588db429
commit 3c08e3a3f1
5 changed files with 21 additions and 8 deletions

View File

@ -29,3 +29,4 @@ vue/babel.config*
vue/package.json vue/package.json
vue/tsconfig.json vue/tsconfig.json
vue/src/utils/openapi vue/src/utils/openapi
venv/

View File

@ -1454,7 +1454,7 @@ def import_files(request):
""" """
limit, msg = above_space_limit(request.space) limit, msg = above_space_limit(request.space)
if limit: if limit:
return Response({'error': msg}, status=status.HTTP_400_BAD_REQUEST) return Response({'error': True, 'msg': _('File is above space limit')}, status=status.HTTP_400_BAD_REQUEST)
form = ImportForm(request.POST, request.FILES) form = ImportForm(request.POST, request.FILES)
if form.is_valid() and request.FILES != {}: if form.is_valid() and request.FILES != {}:

View File

@ -669,8 +669,7 @@ export default {
if (url !== '') { if (url !== '') {
this.failed_imports.push(url) this.failed_imports.push(url)
} }
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_FETCH, err) StandardToasts.makeStandardToast(this, StandardToasts.FAIL_IMPORT, err)
throw "Load Recipe Error"
}) })
}, },
/** /**
@ -713,8 +712,7 @@ export default {
axios.post(resolveDjangoUrl('view_import'), formData, {headers: {'Content-Type': 'multipart/form-data'}}).then((response) => { axios.post(resolveDjangoUrl('view_import'), formData, {headers: {'Content-Type': 'multipart/form-data'}}).then((response) => {
window.location.href = resolveDjangoUrl('view_import_response', response.data['import_id']) window.location.href = resolveDjangoUrl('view_import_response', response.data['import_id'])
}).catch((err) => { }).catch((err) => {
console.log(err) StandardToasts.makeStandardToast(this, StandardToasts.FAIL_IMPORT, err)
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE)
}) })
}, },
/** /**

View File

@ -7,6 +7,7 @@
"err_deleting_protected_resource": "The object you are trying to delete is still used and can't be deleted.", "err_deleting_protected_resource": "The object you are trying to delete is still used and can't be deleted.",
"err_moving_resource": "There was an error moving a resource!", "err_moving_resource": "There was an error moving a resource!",
"err_merging_resource": "There was an error merging a resource!", "err_merging_resource": "There was an error merging a resource!",
"err_importing_recipe": "There was an error importing the recipe!",
"success_fetching_resource": "Successfully fetched a resource!", "success_fetching_resource": "Successfully fetched a resource!",
"success_creating_resource": "Successfully created a resource!", "success_creating_resource": "Successfully created a resource!",
"success_updating_resource": "Successfully updated a resource!", "success_updating_resource": "Successfully updated a resource!",

View File

@ -50,6 +50,7 @@ export class StandardToasts {
static FAIL_DELETE_PROTECTED = "FAIL_DELETE_PROTECTED" static FAIL_DELETE_PROTECTED = "FAIL_DELETE_PROTECTED"
static FAIL_MOVE = "FAIL_MOVE" static FAIL_MOVE = "FAIL_MOVE"
static FAIL_MERGE = "FAIL_MERGE" static FAIL_MERGE = "FAIL_MERGE"
static FAIL_IMPORT = "FAIL_IMPORT"
static makeStandardToast(context, toast, err = undefined, always_show_errors = false) { static makeStandardToast(context, toast, err = undefined, always_show_errors = false) {
let title = '' let title = ''
@ -122,6 +123,11 @@ export class StandardToasts {
title = i18n.tc("Failure") title = i18n.tc("Failure")
msg = i18n.tc("err_merging_resource") msg = i18n.tc("err_merging_resource")
break break
case StandardToasts.FAIL_IMPORT:
variant = 'danger'
title = i18n.tc("Failure")
msg = i18n.tc("err_importing_recipe")
break
} }
@ -131,12 +137,19 @@ export class StandardToasts {
console.trace(); console.trace();
} }
if (err !== undefined && 'response' in err && 'headers' in err.response) { if (err !== undefined
if (DEBUG && err.response.headers['content-type'] === 'application/json' && err.response.status < 500) { && 'response' in err
&& 'headers' in err.response
&& err.response.headers['content-type'] === 'application/json'
&& err.response.status < 500
&& err.response.data) {
// If the backend provides us with a nice error message, we print it, regardless of DEBUG mode
if (DEBUG || err.response.data.msg) {
const errMsg = err.response.data.msg ? err.response.data.msg : JSON.stringify(err.response.data)
msg = context.$createElement('div', {}, [ msg = context.$createElement('div', {}, [
context.$createElement('span', {}, [msg]), context.$createElement('span', {}, [msg]),
context.$createElement('br', {}, []), context.$createElement('br', {}, []),
context.$createElement('code', {'class': 'mt-2'}, [JSON.stringify(err.response.data)]) context.$createElement('code', {'class': 'mt-2'}, [errMsg])
]) ])
} }
} }