-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add type guards for errors #15
Conversation
} | ||
|
||
export function isAutopilotError(error: unknown): error is AutopilotError { | ||
return isObject(error) && typeof error.errorCode === 'string' && typeof error.message === 'string' |
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.
I think the errorCode
is part of the message, e.g.:
{
"response": {
"cause": {},
"response": {},
"url": "http://api.autopilot.local/v1/projects/17d18e41-d104-4053-88c3-f052037d7a94/integrations/git",
"message": "{\"message\":\"Integration not found\",\"errorCode\":\"ENTITY_NOT_FOUND\"}",
"json": {
"message": "Integration not found",
"errorCode": "ENTITY_NOT_FOUND"
},
"text": "{\"message\":\"Integration not found\",\"errorCode\":\"ENTITY_NOT_FOUND\"}",
"status": 404
}
}
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.
Discussed with Arthur offline. We can do the check like this:
if (isAutopilotError(response.json))
However, we already can do this as well:
const autopilotError = COMMON_ERROR_RESPONSE_SCHEMA.parse(response.json)
@szymonchudy @ondrejsevcik Thoughts on whether we need the type guard, or just the schema is sufficient?
…o feat/error-type-guards # Conflicts: # packages/app/api-common/package.json
Currently blocked by https://github.com/lokalise/node-core/pull/89/files |
No description provided.