Skip to content

Commit 473d2d8

Browse files
fix(compat): set class .name on OAuth subclass factory to match v1 named declarations
1 parent 582ac67 commit 473d2d8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/core/src/errors/oauthErrorsCompat.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ type OAuthErrorSubclass = {
1616
};
1717

1818
function sub(code: OAuthErrorCode, name: string): OAuthErrorSubclass {
19-
return class extends OAuthError {
19+
const Sub = class extends OAuthError {
2020
static errorCode = code as string;
2121
constructor(message: string, errorUri?: string) {
2222
super(code, message, errorUri);
2323
this.name = name;
2424
}
2525
};
26+
Object.defineProperty(Sub, 'name', { value: name, configurable: true });
27+
return Sub;
2628
}
2729

2830
/* eslint-disable @typescript-eslint/naming-convention */

packages/core/test/errors/compat.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ describe('v1-compat error aliases', () => {
4343
spy.mockRestore();
4444
});
4545

46+
it('OAuth subclass class .name matches v1 named-declaration behavior', () => {
47+
expect(InvalidTokenError.name).toBe('InvalidTokenError');
48+
const e = new InvalidTokenError('expired');
49+
expect(e.name).toBe('InvalidTokenError');
50+
expect(e.constructor.name).toBe('InvalidTokenError');
51+
});
52+
4653
it('subclass static errorCode and toResponseObject() match v1 wire format', () => {
4754
expect(ServerError.errorCode).toBe('server_error');
4855
const e = new ServerError('boom');

0 commit comments

Comments
 (0)