Handle different form responses

This commit is contained in:
Oliver 2021-07-02 16:53:56 +10:00
parent 9927b597c3
commit 52952a8a8b

View File

@ -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;
}