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

Error handling proposal #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mprudnik
Copy link

I don't know if this is the correct way of passing the error class between files in API, but this is how in theory error should be used.
The idea is to have one error.js file in each unit, where you can describe expected errors for the whole unit.

Comment on lines +2 to +6
AuthError: class AuthError extends DomainError {
static ALREADY_EXISTS() {
return new AuthError(409, { message: 'User already exists' });
}
static INVALID_CREDENTIALS() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not create separate AuthError classes instead?

class AuthError extends DomainError { code: 401 }
class AuthExistsError extends AuthError { code: 409 }
class AuthInvalidCredentialsError extends AuthError { code 400 }
...

it should be simpler to manage and use.

Comment on lines +17 to +20
onError(error) {
const { ExampleError } = api.example.error;
// in theory there's no need to trigger onError handler
if (error instanceof ExampleError) return error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO - this should be default behavior of server for DomainErrors with user-error-format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants