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

Request: Default template string #28

Open
cableray opened this issue Jan 13, 2023 · 1 comment
Open

Request: Default template string #28

cableray opened this issue Jan 13, 2023 · 1 comment

Comments

@cableray
Copy link

It would be nice to call an error like so:

class CustomError extends SError {
  static defaultTemplate =  'there was a problem with foo: {foo}'
}

error = CustomError.create({foo: 'bar'})
// => error.message = 'there was a problem with foo: bar'

Having the message template defined with the error seems to separate responsibilities better: the error message knows how to display the error, and the call-site does not need to know that. Seems to me to better design in some cases, by moving more logic to the error object and away from the call-site.

@Raynos
Copy link
Owner

Raynos commented Jan 13, 2023

In my experience generally the template and message is done at the allocation call site when an error happens.

There can be multiple different ways to create a NetworkError for example and they can have different templates.

Having a shared/common default template or creating a new class for every single type of error branch does not seem practical to me.

For the same reason having a static message or default message for each Error class also does not seem practical.

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

No branches or pull requests

2 participants