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

refactor(js): assign LogtoError code to message #133

Closed
wants to merge 1 commit into from
Closed

Conversation

IceHe
Copy link
Contributor

@IceHe IceHe commented Jan 21, 2022

Summary

refactor(js): assign LogtoError code to message too


Problem:

  test('callback uri, without code, should throw', () => {
    ……
    expect(() => ……).toThrowError(new LogtoError('callbackUri.missingCode'));
  });

is as same as

  test('callback uri, without code, should throw', () => {
    ……
    expect(() => ……).toThrowError();
  });

because

/**
 * If you want to test that a specific error is thrown inside a function.
 */
toThrowError(error?: string | Constructable | RegExp | Error): R;

toThrowError can only check the properties (e.g. message) defined in Error,
and cannot check the properties (e.g. code) defined in classes extends from Error.

My solution is to assign the property LogtoError.code to its parent class property Error.message
so that toThrowError can assert the content of LogtoError.code.

Linear Issue Reference

Related #127 #131 LOG-1355 LOG1356

Testing

Pass all existing unit tests.


@logto-io/eng

@IceHe IceHe marked this pull request as draft January 21, 2022 11:50
@IceHe IceHe changed the title refactor(js): assign LogtoError code to message too refactor(js): assign LogtoError code to message Jan 21, 2022
@gao-sun
Copy link
Member

gao-sun commented Jan 21, 2022

@IceHe IceHe marked this pull request as ready for review January 21, 2022 12:04
@IceHe
Copy link
Contributor Author

IceHe commented Jan 21, 2022

Follow the best practice.

@IceHe IceHe closed this Jan 21, 2022
@IceHe IceHe deleted the icehe-chore branch January 28, 2022 06:35
@IceHe IceHe restored the icehe-chore branch January 28, 2022 06:35
@IceHe IceHe deleted the icehe-chore branch January 28, 2022 06:35
@IceHe IceHe added the enhancement To make it better label Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement To make it better
Development

Successfully merging this pull request may close these issues.

2 participants