Skip to content

Commit 43e8e7d

Browse files
authored
Merge branch 'alpha' into event-emitter
2 parents 5e5768a + c6ffeb2 commit 43e8e7d

9 files changed

+71
-7
lines changed

changelogs/CHANGELOG_alpha.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# [4.2.0-alpha.9](https://github.com/parse-community/Parse-SDK-JS/compare/4.2.0-alpha.8...4.2.0-alpha.9) (2023-09-01)
2+
3+
4+
### Features
5+
6+
* Allow overriding `Parse.Error` message with custom message via new Core Manager option `PARSE_ERRORS` ([#2014](https://github.com/parse-community/Parse-SDK-JS/issues/2014)) ([be0c8a6](https://github.com/parse-community/Parse-SDK-JS/commit/be0c8a6ff90a7714487ae793e2b68ae04d0c8d0c))
7+
8+
# [4.2.0-alpha.8](https://github.com/parse-community/Parse-SDK-JS/compare/4.2.0-alpha.7...4.2.0-alpha.8) (2023-08-30)
9+
10+
11+
### Features
12+
13+
* Add Cloud Code context accessibility to `ParseUser.logIn` ([#2010](https://github.com/parse-community/Parse-SDK-JS/issues/2010)) ([2446007](https://github.com/parse-community/Parse-SDK-JS/commit/2446007ede4cc5af79e34f27dc1fbcc574d5f717))
14+
115
# [4.2.0-alpha.7](https://github.com/parse-community/Parse-SDK-JS/compare/4.2.0-alpha.6...4.2.0-alpha.7) (2023-08-29)
216

317

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse",
3-
"version": "4.2.0-alpha.7",
3+
"version": "4.2.0-alpha.9",
44
"description": "Parse JavaScript SDK",
55
"homepage": "https://parseplatform.org",
66
"keywords": [

src/CoreManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ const config: Config & { [key: string]: mixed } = {
194194
ENCRYPTED_USER: false,
195195
IDEMPOTENCY: false,
196196
ALLOW_CUSTOM_OBJECT_ID: false,
197+
PARSE_ERRORS: [],
197198
};
198199

199200
function requireMethods(name: string, methods: Array<string>, controller: any) {

src/EventuallyQueue.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import CoreManager from './CoreManager';
8+
import ParseError from './ParseError';
89
import ParseObject from './ParseObject';
910
import ParseQuery from './ParseQuery';
1011
import Storage from './Storage';
@@ -275,7 +276,7 @@ const EventuallyQueue = {
275276
await object.save(queueObject.object, queueObject.serverOptions);
276277
await this.remove(queueObject.queueId);
277278
} catch (e) {
278-
if (e.message !== 'XMLHttpRequest failed: "Unable to connect to the Parse API"') {
279+
if (e.code !== ParseError.CONNECTION_FAILED) {
279280
await this.remove(queueObject.queueId);
280281
}
281282
}
@@ -285,7 +286,7 @@ const EventuallyQueue = {
285286
await object.destroy(queueObject.serverOptions);
286287
await this.remove(queueObject.queueId);
287288
} catch (e) {
288-
if (e.message !== 'XMLHttpRequest failed: "Unable to connect to the Parse API"') {
289+
if (e.code !== ParseError.CONNECTION_FAILED) {
289290
await this.remove(queueObject.queueId);
290291
}
291292
}

src/ParseError.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import CoreManager from './CoreManager';
2+
13
/**
24
* Constructs a new Parse.Error object with the given code and message.
35
*
6+
* Parse.CoreManager.set('PARSE_ERRORS', [{ code, message }]) can be use to override error messages.
7+
*
48
* @alias Parse.Error
59
*/
610
class ParseError extends Error {
@@ -11,9 +15,15 @@ class ParseError extends Error {
1115
constructor(code, message) {
1216
super(message);
1317
this.code = code;
18+
let customMessage = message;
19+
CoreManager.get('PARSE_ERRORS').forEach((error) => {
20+
if (error.code === code && error.code) {
21+
customMessage = error.message;
22+
}
23+
});
1424
Object.defineProperty(this, 'message', {
1525
enumerable: true,
16-
value: message,
26+
value: customMessage,
1727
});
1828
}
1929

src/ParseUser.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,12 @@ class ParseUser extends ParseObject {
469469
if (options.hasOwnProperty('usePost')) {
470470
loginOptions.usePost = options.usePost;
471471
}
472-
472+
if (
473+
options.hasOwnProperty('context') &&
474+
Object.prototype.toString.call(options.context) === '[object Object]'
475+
) {
476+
loginOptions.context = options.context;
477+
}
473478
const controller = CoreManager.getUserController();
474479
return controller.logIn(this, loginOptions);
475480
}

src/__tests__/ParseError-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
jest.dontMock('../ParseError');
2+
jest.dontMock('../CoreManager');
23

34
const ParseError = require('../ParseError').default;
5+
const CoreManager = require('../CoreManager');
46

57
describe('ParseError', () => {
68
it('have sensible string representation', () => {
@@ -18,4 +20,14 @@ describe('ParseError', () => {
1820
code: 123,
1921
});
2022
});
23+
24+
it('can override message', () => {
25+
CoreManager.set('PARSE_ERRORS', [{ code: 123, message: 'Oops.' }]);
26+
const error = new ParseError(123, 'some error message');
27+
expect(JSON.parse(JSON.stringify(error))).toEqual({
28+
message: 'Oops.',
29+
code: 123,
30+
});
31+
CoreManager.set('PARSE_ERRORS', []);
32+
});
2133
});

src/__tests__/ParseUser-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,27 @@ describe('ParseUser', () => {
19421942
expect(controller.request.mock.calls[0][3].context).toEqual(context);
19431943
});
19441944

1945+
it('can login with context', async () => {
1946+
CoreManager.setRESTController({
1947+
ajax() {},
1948+
request() {
1949+
return Promise.resolve(
1950+
{
1951+
objectId: 'uid33',
1952+
username: 'username',
1953+
sessionToken: '123abc',
1954+
},
1955+
200
1956+
);
1957+
},
1958+
});
1959+
const controller = CoreManager.getRESTController();
1960+
jest.spyOn(controller, 'request');
1961+
const context = { a: 'a' };
1962+
await ParseUser.logIn('username', 'password', { context });
1963+
expect(controller.request.mock.calls[0][3].context).toEqual(context);
1964+
});
1965+
19451966
it('can verify user password', async () => {
19461967
ParseUser.enableUnsafeCurrentUser();
19471968
ParseUser._clearCache();

0 commit comments

Comments
 (0)