Skip to content

Commit f04f51f

Browse files
committed
Expose error in _linkWith recursive call
1 parent c3a2a73 commit f04f51f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/ParseUser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export default class ParseUser extends ParseObject {
108108
}
109109
this._linkWith(provider, opts).then(() => {
110110
promise.resolve(this);
111+
}, (error) => {
112+
promise.reject(error);
111113
});
112114
},
113115
error: (provider, error) => {

src/__tests__/ParseUser-test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var ParseObject = require('../ParseObject');
3232
var ParsePromise = require('../ParsePromise');
3333
var ParseUser = require('../ParseUser');
3434
var Storage = require('../Storage');
35+
var ParseError = require('../ParseError');
3536

3637
var asyncHelper = require('./test_helpers/asyncHelper');
3738

@@ -360,4 +361,49 @@ describe('ParseUser', () => {
360361
done();
361362
});
362363
}));
364+
365+
it('can get error when recursive _linkWith call fails', asyncHelper((done) => {
366+
CoreManager.setRESTController({
367+
request(method, path, body, options) {
368+
expect(method).toBe('POST');
369+
expect(path).toBe('users');
370+
expect(body.authData.test).toEqual({
371+
id : 'id',
372+
access_token : 'access_token'
373+
});
374+
var error = new ParseError(
375+
ParseError.ACCOUNT_ALREADY_LINKED,
376+
'Another user is already linked to this facebook id.'
377+
);
378+
return ParsePromise.error(error);
379+
},
380+
ajax() {}
381+
});
382+
var provider = {
383+
authenticate(options) {
384+
if (options.success) {
385+
options.success(this, {
386+
id: 'id',
387+
access_token: 'access_token'
388+
});
389+
}
390+
},
391+
392+
restoreAuthentication(authData) {},
393+
394+
getAuthType() {
395+
return 'test';
396+
},
397+
398+
deauthenticate() {}
399+
};
400+
401+
ParseUser.logInWith(provider, {}).then(() => {
402+
403+
}, (error) => {
404+
expect(error.code).toBe(ParseError.ACCOUNT_ALREADY_LINKED);
405+
expect(error.message).toBe('Another user is already linked to this facebook id.');
406+
done();
407+
});
408+
}));
363409
});

0 commit comments

Comments
 (0)