Skip to content

Commit f91f3f1

Browse files
authored
fix: Missing error message when returning an internal server error (#2543)
1 parent f2ca7a6 commit f91f3f1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/RESTController.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ const RESTController = {
334334
if (response && response.responseText) {
335335
try {
336336
const errorJSON = JSON.parse(response.responseText);
337-
error = new ParseError(errorJSON.code, errorJSON.error);
337+
error = new ParseError(errorJSON.code, errorJSON.error || errorJSON.message);
338338
} catch (_) {
339339
// If we fail to parse the error text, that's okay.
340340
error = new ParseError(

src/__tests__/RESTController-test.js

+19
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,25 @@ describe('RESTController', () => {
175175
});
176176
});
177177

178+
it('handles request errors with message', done => {
179+
RESTController._setXHR(
180+
mockXHR([
181+
{
182+
status: 400,
183+
response: {
184+
code: 1,
185+
message: 'Internal server error.',
186+
},
187+
},
188+
])
189+
);
190+
RESTController.request('GET', 'classes/MyObject', {}, {}).then(null, error => {
191+
expect(error.code).toBe(1);
192+
expect(error.message).toBe('Internal server error.');
193+
done();
194+
});
195+
});
196+
178197
it('handles invalid responses', done => {
179198
const XHR = function () {};
180199
XHR.prototype = {

0 commit comments

Comments
 (0)