Skip to content

Commit 38fe34e

Browse files
Add rawData to OauthException (#847)
## Description This PR adds the `rawData` field containing the raw error response data to the `OauthException`s thrown by the SDK. Resolves USRLD-1006. ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required. Co-authored-by: Dane Williams <[email protected]>
1 parent ee0666f commit 38fe34e

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
export class GenericServerException extends Error {
22
readonly name: string = 'GenericServerException';
3-
readonly rawData: unknown;
43
readonly message: string = 'The request could not be completed.';
54

65
constructor(
76
readonly status: number,
87
message: string | undefined,
9-
rawData: unknown,
8+
readonly rawData: unknown,
109
readonly requestID: string,
1110
) {
1211
super();
1312
if (message) {
1413
this.message = message;
15-
this.rawData = rawData;
1614
}
1715
}
1816
}

src/common/exceptions/oauth.exception.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class OauthException extends Error {
66
readonly requestID: string,
77
readonly error: string | undefined,
88
readonly errorDescription: string | undefined,
9+
readonly rawData: unknown,
910
) {
1011
super();
1112
if (error && errorDescription) {

src/workos.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ describe('WorkOS', () => {
198198
const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
199199

200200
await expect(workos.post('/path', {})).rejects.toStrictEqual(
201-
new OauthException(400, 'a-request-id', 'error', 'error description'),
201+
new OauthException(
202+
400,
203+
'a-request-id',
204+
'error',
205+
'error description',
206+
{ error: 'error', error_description: 'error description' },
207+
),
202208
);
203209
});
204210
});

src/workos.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export class WorkOS {
219219
requestID,
220220
error,
221221
errorDescription,
222+
data,
222223
);
223224
} else if (code && errors) {
224225
// Note: ideally this should be mapped directly with a `400` status code.

0 commit comments

Comments
 (0)