Skip to content

Commit

Permalink
feat(authentication-client): Throw separate OauthError in authenticat…
Browse files Browse the repository at this point in the history
…ion client (#2189)
  • Loading branch information
daffl committed Jan 16, 2021
1 parent 806a296 commit fa45ec5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/authentication-client/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { Application, Params } from '@feathersjs/feathers';
import { AuthenticationRequest, AuthenticationResult } from '@feathersjs/authentication';
import { Storage, StorageWrapper } from './storage';

class OauthError extends FeathersError {
constructor (message: string, data?: any) {
super(message, 'OauthError', 401, 'oauth-error', data);
}
}

const getMatch = (location: Location, key: string): [ string, RegExp ] => {
const regex = new RegExp(`(?:\&?)${key}=([^&]*)`);
const match = location.hash ? location.hash.match(regex) : null;
Expand Down Expand Up @@ -90,7 +96,7 @@ export class AuthenticationClient {
if (message !== null) {
location.hash = location.hash.replace(errorRegex, '');

return Promise.reject(new NotAuthenticated(decodeURIComponent(message)));
return Promise.reject(new OauthError(decodeURIComponent(message)));
}

return Promise.resolve(null);
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-client/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('@feathersjs/authentication-client', () => {
} as Location);
assert.fail('Should never get here');
} catch (error) {
assert.strictEqual(error.name, 'NotAuthenticated');
assert.strictEqual(error.name, 'OauthError');
assert.strictEqual(error.message, 'Error Happened');
}
});
Expand Down

0 comments on commit fa45ec5

Please sign in to comment.