Skip to content

Commit 2aa0d56

Browse files
fix: error serialization (#384)
Co-authored-by: Rishabh Poddar <[email protected]>
1 parent b46506a commit 2aa0d56

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [12.0.0] - 2022-09-14
1111

12+
### Bug fix:
13+
14+
- Makes `SuperTokensError` extend the built-in `Error` class to fix serialization issues.
15+
1216
### Changed
1317

1418
- Made the `email` parameter option in `unverifyEmail`, `revokeEmailVerificationTokens`, `isEmailVerified`, `verifyEmailUsingToken`, `createEmailVerificationToken` of the `EmailVerification` recipe.

lib/build/error.d.ts

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/error.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/error.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
* under the License.
1414
*/
1515

16-
export default class SuperTokensError {
16+
export default class SuperTokensError extends Error {
1717
private static errMagic = "ndskajfasndlfkj435234krjdsa";
1818
static BAD_INPUT_ERROR: "BAD_INPUT_ERROR" = "BAD_INPUT_ERROR";
1919

2020
public type: string;
21-
public message: string;
2221
public payload: any;
2322

2423
// this variable is used to identify which
@@ -44,8 +43,8 @@ export default class SuperTokensError {
4443
payload: undefined;
4544
}
4645
) {
46+
super(options.message);
4747
this.type = options.type;
48-
this.message = options.message;
4948
this.payload = options.payload;
5049
this.errMagic = SuperTokensError.errMagic;
5150
}

test/error.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const assert = require("assert");
2+
const { default: SuperTokensError } = require("../lib/build/error");
3+
4+
describe("SuperTokensError", () => {
5+
it("should serialize with the proper message", () => {
6+
const err = new SuperTokensError({ type: SuperTokensError.BAD_INPUT_ERROR, message: "test message" });
7+
8+
assert.strictEqual(err.toString(), "Error: test message");
9+
});
10+
});

0 commit comments

Comments
 (0)