diff --git a/package.json b/package.json index d3d6fbc..1ab0d23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "django-bananas", - "version": "4.1.1", + "version": "4.1.2", "license": "MIT", "author": "Jonas Lundberg", "repository": { @@ -10,13 +10,7 @@ "description": "React admin frontend for Django.", "main": "index.js", "private": true, - "keywords": [ - "admin", - "bananas", - "django", - "django-admin", - "react" - ], + "keywords": ["admin", "bananas", "django", "django-admin", "react"], "scripts": { "start": "webpack-dev-server --config app/webpack.config.js", "watch": "jest --watchAll --verbose", diff --git a/src/Admin.js b/src/Admin.js index 8dde9b8..4f41702 100644 --- a/src/Admin.js +++ b/src/Admin.js @@ -206,7 +206,7 @@ class Admin extends React.Component { }); } catch (error) { logger.error("Critical Error: Failed to initialize API client!", error); - const cause = error.response ? error.response.statusText : "Unreachable"; + const cause = error?.response?.statusText ?? "Unreachable"; this.admin.error(`Failed to boot: API ${cause}`); this.setState({ booting: false }); return; diff --git a/src/api.js b/src/api.js index fc4bb7d..ed3b0f9 100644 --- a/src/api.js +++ b/src/api.js @@ -60,7 +60,7 @@ class APIClient extends Swagger { const message = response.obj && response.obj.detail ? response.obj.detail - : `API ${response.statusText}`; + : `API ${response?.statusText ?? "Unknown error"}`; this.errorHandler(message); }; diff --git a/src/forms/Form.js b/src/forms/Form.js index ebd1a96..2598d88 100644 --- a/src/forms/Form.js +++ b/src/forms/Form.js @@ -51,7 +51,7 @@ class Form extends React.Component { this.context.api[route]({ ...params, ...passedParams, - data: data || values, + data: data ?? values, }); const promise = onSubmit ? Promise.resolve(onSubmit({ endpoint, values })) @@ -65,12 +65,13 @@ class Form extends React.Component { return false; }); - return promise.catch(({ response: { statusText, status, obj } }) => { + return promise.catch(({ response: { obj, ...response } }) => { const errorMessages = { 400: "Please correct the errors on this form.", }; this.context.admin.error( - errorMessages[status] || `${status} : ${statusText}` + errorMessages?.[response?.status] ?? + `${response?.status ?? "Unknown status"} : ${response?.statusText ?? "Unknown cause"}` ); return normalizeFormErrorData(obj); });