-
Notifications
You must be signed in to change notification settings - Fork 6
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
change(api-client-core): Error definitions #183
Conversation
39ef92d
to
6bf59e3
Compare
9bb7bd7
to
1950097
Compare
@@ -218,7 +234,7 @@ export const getNonNullableError = (response: Result & { fetching: boolean }, da | |||
`Internal Error: Gadget API didn't return expected data. Nothing found in response at ${dataPath.join(".")}` | |||
); | |||
} else if (result === null || (throwOnEmptyData && Array.isArray(dataArray) && dataArray.length === 0)) { | |||
return new GadgetInternalError(`Internal Error: Gadget API returned no data at ${dataPath.join(".")}`); | |||
return new GadgetNotFoundError(`Internal Error: Gadget API returned no data at ${dataPath.join(".")}`); |
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.
js-clients/packages/api-client-core/src/support.ts
Lines 155 to 160 in 1950097
/** | |
* A Gadget API error that represents an error where the client asked the server for data that doesn't exist server side. | |
*/ | |
export class GadgetNotFoundError extends Error { | |
code = "GGT_RECORD_NOT_FOUND"; | |
} |
1950097
to
b1cee56
Compare
0b12975
to
69d59ba
Compare
/** @private */ | ||
statusCode = 500; | ||
/** @private */ | ||
causedByClient = true; |
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.
Shouldn't this be false
?
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.
My rationale was that if there was a GadgetInternalError then the client (The gadget platform) is at fault here - i.e. "caused" this error to be thrown. My interpretation could be wrong. Lmk if you disagree
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.
Haha, oh man I have no idea what causedByClient
means anymore. You could very well be correct, but GadgetClientError
having causedByClient = false
and GadgetInternalError
having causedByClient = true
makes my brain 🤯
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.
My rationale was that if there was a GadgetInternalError then the client (The gadget platform) is at fault here - i.e. "caused" this error to be thrown. My interpretation could be wrong. Lmk if you disagree
I think you are getting this backwards.
The gadget client is this code, the js-client
.
causedByClient
can be reworded as a 4xx HTTP status code, it means incorrect args were sent from the client. And we should not report this to sentry. An example is findOne(...)
for an ID that doesn't exist.
GadgetInternalError
means the Gadget servers returned invalid data, in that case causedByClient = false
.
69d59ba
to
9d58152
Compare
9d58152
to
90bef57
Compare
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.
LGTM 👍
Changing the error definitions and added missing attributes for errors coming out of the client. We're doing this because of the errors already defined e.g.
GadgetInternalError
weren't being used in appropriate spots.PR Checklist