From 52952a8a8ba6a36e1dbc235be02926311419b229 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 2 Jul 2021 16:53:56 +1000 Subject: [PATCH] Handle different form responses --- InvenTree/templates/js/forms.js | 41 ++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index cb505c2a11..68eda4b734 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -532,10 +532,49 @@ function submitFormData(fields, options) { error: function(xhr, status, thrownError) { switch (xhr.status) { - case 400: // Bad request + case 400: // Bad request handleFormErrors(xhr.responseJSON, fields, options); break; + case 0: // No response + $(options.modal).modal('hide'); + showAlertDialog( + '{% trans "No Response" %}', + '{% trans "No response from the InvenTree server" %}', + ); + break; + case 401: // Not authenticated + $(options.modal).modal('hide'); + showAlertDialog( + '{% trans "Error 401: Not Authenticated" %}', + '{% trans "Authentication credentials not supplied" %}', + ); + break; + case 403: // Permission denied + $(options.modal).modal('hide'); + showAlertDialog( + '{% trans "Error 403: Permission Denied" %}', + '{% trans "You do not have the required permissions to access this function" %}', + ); + break; + case 404: // Resource not found + $(options.modal).modal('hide'); + showAlertDialog( + '{% trans "Error 404: Resource Not Found" %}', + '{% trans "The requested resource could not be located on the server" %}', + ); + break; + case 408: // Timeout + $(options.modal).modal('hide'); + showAlertDialog( + '{% trans "Error 408: Timeout" %}', + '{% trans "Connection timeout while requesting data from server" %}', + ); + break; default: + $(options.modal).modal('hide'); + + showAlertDialog('{% trans "Error requesting form data" %}', renderErrorMessage(xhr)); + console.log(`WARNING: Unhandled response code - ${xhr.status}`); break; }