Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/vabene1111/recipes into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
vabene1111 committed Nov 29, 2023
2 parents e907819 + 8649606 commit 4844e5c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cookbook/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ def import_files(request):
"""
limit, msg = above_space_limit(request.space)
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)
if form.is_valid() and request.FILES != {}:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Django==4.2.7
cryptography===41.0.4
cryptography===41.0.6
django-annoying==0.10.6
django-autocomplete-light==3.9.4
django-cleanup==8.0.0
Expand Down
6 changes: 2 additions & 4 deletions vue/src/apps/ImportView/ImportView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,7 @@ export default {
if (url !== '') {
this.failed_imports.push(url)
}
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_FETCH, err)
throw "Load Recipe Error"
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_IMPORT, err)
})
},
/**
Expand Down Expand Up @@ -713,8 +712,7 @@ export default {
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'])
}).catch((err) => {
console.log(err)
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE)
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_IMPORT, err)
})
},
/**
Expand Down
1 change: 1 addition & 0 deletions vue/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"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_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_creating_resource": "Successfully created a resource!",
"success_updating_resource": "Successfully updated a resource!",
Expand Down
19 changes: 16 additions & 3 deletions vue/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class StandardToasts {
static FAIL_DELETE_PROTECTED = "FAIL_DELETE_PROTECTED"
static FAIL_MOVE = "FAIL_MOVE"
static FAIL_MERGE = "FAIL_MERGE"
static FAIL_IMPORT = "FAIL_IMPORT"

static makeStandardToast(context, toast, err = undefined, always_show_errors = false) {
let title = ''
Expand Down Expand Up @@ -122,6 +123,11 @@ export class StandardToasts {
title = i18n.tc("Failure")
msg = i18n.tc("err_merging_resource")
break
case StandardToasts.FAIL_IMPORT:
variant = 'danger'
title = i18n.tc("Failure")
msg = i18n.tc("err_importing_recipe")
break
}


Expand All @@ -131,12 +137,19 @@ export class StandardToasts {
console.trace();
}

if (err !== undefined && 'response' in err && 'headers' in err.response) {
if (DEBUG && err.response.headers['content-type'] === 'application/json' && err.response.status < 500) {
if (err !== undefined
&& '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', {}, [
context.$createElement('span', {}, [msg]),
context.$createElement('br', {}, []),
context.$createElement('code', {'class': 'mt-2'}, [JSON.stringify(err.response.data)])
context.$createElement('code', {'class': 'mt-2'}, [errMsg])
])
}
}
Expand Down

0 comments on commit 4844e5c

Please sign in to comment.