-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[cdnjs gem] make exception classes more consistent #1683
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks overall good to me! 👍
Minor observation: should we keep a more informative message for the InvalidResponse
s in gem.js ("version is null", "info is invalid")?
I was in 2 minds about whether it is useful to wrap a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Left a couple of notes on some things i wasn't sure about though.
services/errors.js
Outdated
|
||
constructor(props) { | ||
props = props || {}; | ||
const prettyMessage = props.prettyMessage || 'not found'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this line (& line below) be using this.defaultPrettyMessage
in place of 'not found'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be ideal, but there's a catch 22:
If we try to reference this
before super()
, error 'this' is not allowed before 'super()'
is thrown (which makes sense), but we need to assemble message
before we can call super()
.
Maybe an alternative would be to declare the default messages as constants outside the classes so we can say
const defaultNotFoundMessage = 'not found';
class NotFound extends ShieldsRuntimeError {
get name() { return 'NotFound'; }
get defaultPrettyMessage() { return defaultNotFoundMessage; }
constructor(props = {}) {
const prettyMessage = props.prettyMessage || defaultNotFoundMessage;
//...
}
}
do you think that is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah that makes sense, sounds good to me 👍
You can keep it how it is or change it, whichever makes the most sense for you.
services/errors.js
Outdated
get defaultPrettyMessage() { return 'not found'; } | ||
|
||
constructor(props) { | ||
props = props || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would we be better to remove this line and declare the default value in the header instead?
constructor(props = {}) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 updated
As I've been working on the new service code, I've had a couple of thoughts on the exception classes:
#1590 (comment)
#1680 (comment)
I think its worth looking at this before we are using this code in too many places and it becomes difficult to change the constructor signatures. This PR proposes the following changes:
Passing a
props
object meansunderlyingError
andprettyMessage
are always optional. This means we don't need to use workarounds likethrow new InvalidResponse(undefined, err);
orthrow new InvalidResponse('invalid', new Error());
if we don't want to customise the error or don't have an exception to wrap.Declare a base class which our runtime exceptions inherit from
does this seem like a reasonable approach?