Skip to content

Commit 66cf20a

Browse files
committed
Merge pull request #34 from ParsePlatform/wangmengyan.expose_linkWith_exception
Expose error in _linkWith recursive call
2 parents a9b5f94 + 69bcda9 commit 66cf20a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-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: 44 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

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

0 commit comments

Comments
 (0)