Browse Source

Minor updates to Vue.js error handling (to work with new back-end validation)

pull/170/head
Michael Olund 5 years ago
parent
commit
a0a3a7dfb7
2 changed files with 11 additions and 8 deletions
  1. +1
    -1
      edivorce/apps/core/serializer.py
  2. +10
    -7
      vue/src/components/Uploader/Uploader.vue

+ 1
- 1
edivorce/apps/core/serializer.py View File

@ -45,5 +45,5 @@ class DocumentSerializer(serializers.ModelSerializer):
try: try:
response.save() response.save()
except IntegrityError: except IntegrityError:
raise ValidationError("You have already uploaded that file")
raise ValidationError("This file appears to have already been uploaded with for this document. Duplicate filename: " + filename)
return response return response

+ 10
- 7
vue/src/components/Uploader/Uploader.vue View File

@ -161,15 +161,17 @@ export default {
// upload is complete // upload is complete
if (newFile && oldFile && !newFile.active && oldFile.active) { if (newFile && oldFile && !newFile.active && oldFile.active) {
// todo: send metadata to the server
console.log('Upload Complete; file=' + newFile.name)
this.saveMetaData(); this.saveMetaData();
if (newFile.xhr) { if (newFile.xhr) {
// Get the response status code (we can use this for error handling)
if (newFile.xhr.status !== 200) {
// todo: handler errors
// Error Handling
if (newFile.xhr.status === 400) {
// 400 validation error: show the message returned by the server
const message = JSON.parse(newFile.xhr.responseText)[0];
this.showError(message);
this.$refs.upload.remove(newFile);
} else if (newFile.xhr.status !== 200) {
// 500 server error: show the status text and a generic message
this.showError('Error: ' + newFile.xhr.statusText + '. Please try the upload again. If this doesn\'t work, try again later.'); this.showError('Error: ' + newFile.xhr.statusText + '. Please try the upload again. If this doesn\'t work, try again later.');
console.log('status', newFile.xhr.status) console.log('status', newFile.xhr.status)
} }
@ -304,7 +306,8 @@ export default {
created() { created() {
// call the API to update the metadata every second, but only if // call the API to update the metadata every second, but only if
// the data has changed (throttling requests because rotating and // the data has changed (throttling requests because rotating and
// re-ordering images can cause a lot of traffic)
// re-ordering images can cause a lot of traffic and possibly
// result in out-of-order requests)
setInterval(() => { setInterval(() => {
if (this.isDirty) { if (this.isDirty) {
this.saveMetaData(); this.saveMetaData();


Loading…
Cancel
Save