Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(authentication-client): Throw separate OauthError in authentication client #2189

Merged
merged 1 commit into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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