Skip to content

Commit 0bc2230

Browse files
authored
feat(error): keep raw message if keepErrorRawMessage flag is set (#525)
1 parent 9f2ec36 commit 0bc2230

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/init.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ AV._setServerURLs = (urls, disableAppRouter = true) => {
161161
*/
162162
AV.setServerURLs = urls => AV._setServerURLs(urls);
163163

164+
AV.keepErrorRawMessage = value => {
165+
AV._sharedConfig.keepErrorRawMessage = value;
166+
};
167+
164168
// backword compatible
165169
AV.initialize = AV.init;
166170

src/request.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
const _ = require('underscore');
12
const md5 = require('md5');
23
const {
34
extend,
45
} = require('underscore');
56
const Promise = require('./promise');
6-
const AVError = require('./error');
77
const AV = require('./av');
88
const {
99
getSessionToken,
@@ -136,10 +136,15 @@ const request = ({ service, version, method, path, query, data = {}, authOptions
136136
// If we fail to parse the error text, that's okay.
137137
}
138138
}
139-
errorJSON.error += ` [${error.statusCode||'N/A'} ${method} ${url}]`;
139+
errorJSON.rawMessage = errorJSON.rawMessage || errorJSON.error;
140+
if (!AV._sharedConfig.keepErrorRawMessage) {
141+
errorJSON.error += ` [${error.statusCode||'N/A'} ${method} ${url}]`;
142+
}
140143
// Transform the error into an instance of AVError by trying to parse
141144
// the error string as JSON.
142-
throw new AVError(errorJSON.code, errorJSON.error);
145+
const err = new Error(errorJSON.error);
146+
delete errorJSON.error;
147+
throw _.extend(err, errorJSON);
143148
})
144149
);
145150
};

0 commit comments

Comments
 (0)