Skip to content

Commit 4e215bb

Browse files
committed
amend error handling according to status
1 parent 3510258 commit 4e215bb

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

app/controllers/events/view/tickets/orders/list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export default Controller.extend({
9090
if (error.status === 429) {
9191
this.notify.error(this.l10n.t('Only 5 resend actions are allowed in a minute'));
9292
}
93-
if (error.errors[0].detail) {
94-
this.notify.error(this.l10n.t(error.errors[0].detail));
93+
if (error.status === 422) {
94+
this.notify.error(this.l10n.t('Only completed and placed orders can be confirmed'));
9595
}
9696
}
9797
}

app/services/loader.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { buildUrl } from 'open-event-frontend/utils/url';
66
import httpStatus from 'http-status';
77
import objectToFormData from 'object-to-formdata';
88
import fetch from 'fetch';
9-
import { clone, assign, merge } from 'lodash-es';
9+
import { clone, assign, merge, pick, isString } from 'lodash-es';
1010
const bodyAllowedIn = ['PATCH', 'POST', 'PUT'];
1111

1212
export default Service.extend({
@@ -94,20 +94,17 @@ export default Service.extend({
9494

9595
if (!response.ok) {
9696
const defaultMessage = httpStatus[response.status];
97-
if (parsedResponse) {
98-
throw parsedResponse;
99-
}
100-
if (response.status === 429) {
101-
throw {status : 429, message : 'TOO MANY REQUESTS'};
102-
}
103-
throw new Error(
104-
getErrorMessage(
97+
const errorResponse = pick(response, ['status', 'ok', 'statusText', 'headers', 'url']);
98+
errorResponse.statusText = defaultMessage;
99+
errorResponse.response = parsedResponse;
100+
errorResponse.errorMessage = isString(parsedResponse) ? parsedResponse
101+
: getErrorMessage(
105102
response.statusText,
106103
defaultMessage
107104
? `${response.status} - ${defaultMessage}`
108105
: `Could not make ${fetchOptions.type} request to ${fetchOptions.url}`
109-
)
110-
);
106+
);
107+
throw errorResponse;
111108
}
112109
return parsedResponse;
113110
},

0 commit comments

Comments
 (0)