Skip to content

Commit be92cff

Browse files
committed
deposit: fix global server errors in frontend
1 parent 576b243 commit be92cff

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/api/DepositApiClient.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import axios from "axios";
99
import _get from "lodash/get";
10+
import _isEmpty from "lodash/isEmpty";
1011

1112
const BASE_HEADERS = {
1213
"json": { "Content-Type": "application/json" },
@@ -108,7 +109,7 @@ export class RDMDepositApiClient extends DepositApiClient {
108109
error.response.data.errors || []
109110
);
110111
// this is to serialize raised error from the backend on publish
111-
if (errors) errorData = errors;
112+
if (!_isEmpty(errors)) errorData = errors;
112113
throw new DepositApiClientResponse({}, errorData);
113114
}
114115
}

invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/errors/FormFeedback.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ class DisconnectedFormFeedback extends Component {
211211
? "suggestive"
212212
: initialFeedback;
213213

214-
// if no field is specified on the backend, then the message is on the `_schema` field
215-
const backendErrorMessage = errors._schema;
214+
// if no field is specified on the backend, then the validation message is on the `_schema` field
215+
// if the backend returns an explicit message e.g server error, then we use that instead of the default one
216+
const backendErrorMessage = errors.message || errors._schema;
216217

217218
// Retrieve the corresponding icon and type if the feedback is a valid key,
218219
// else fallback to warning.

0 commit comments

Comments
 (0)