-
Notifications
You must be signed in to change notification settings - Fork 0
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
PSG-3862: improve error handling #15
Conversation
src/classes/PassageError.ts
Outdated
readonly statusCode: number | undefined; | ||
readonly error: string | undefined; | ||
readonly message: string; | ||
public readonly status: number | undefined; |
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.
To me these feel backwards - I'd expect a code to be a number and the status to be a string. This is similar to how we define PassageError
in our JS. Does it matter that we diverge on this between Node + client JS, and is this more standard for node error handling?
public statusCode: number;
public statusText: string;
public message: string;
public name: 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 did read the PR description and disambiguating statusCode from HTTP status codes does make sense, just to me code
reads as a numeric error code.
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'm happy to conform to the client packages and swap it so that it'd be something like this
PassageError {
statusCode: 409,
statusText: 'user_has_no_passkeys',
message: 'Could not create authenticate transaction: User has no passkeys',
}
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.
Personally I like keeping things uniform where we can, but if you or Kevin have strong feelings this format no longer makes sense (PassageError and those fields were created over 2 years ago) we could change it. Downside of changing the JS SDK is it'll introduce a potentially breaking change to passageJS consumers so we'd need to handle it accordingly
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.
Changed in f88ec0f
src/index.ts
Outdated
export { | ||
CreateTransactionAuthenticateRequest, | ||
CreateTransactionRegisterRequest, | ||
Model400ErrorCodeEnum, |
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'm aware that these enums are coming from generated code but it would be ideal if they had more user-friendly error enum names that map to the type of error. Might not be particularly easy to do with the codegen core
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 could alias them and export those. I was also going to set the statusText
to a union of those codes
public readonly statusText:
| Model400ErrorCodeEnum
| Model401ErrorCodeEnum
| Model403ErrorCodeEnum
| Model404ErrorCodeEnum
| Model409ErrorCodeEnum
| Model500ErrorCodeEnum
| undefined;
Which would alleviate the need to export them since it would be a string literal union, right?
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.
oh interesting I expected those were an enum of the numbers for the error code not the error message
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.
nvm I see we're mapping response.errorCode to this.statusText
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.
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.
nvm I see we're mapping response.errorCode to
this.statusText
Ah I see the mixup with how the client code defines "ErrorCode". I can rename that to avoid the overloaded term between the sdks
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.
Okay so I pulled up these types and played around with some typescript. I think what you want to do is this - create a merged enum of all these ModelXXXErrorCodeEnum types like so:
export const ErrorStatusText = { ...Model400ErrorCodeEnum, ...Model401ErrorCodeEnum, //and all the rest};
Then set the statusText property to be this enum union:
public readonly statusText: ErrorStatusText | undefined;
This will allow customers to do this kind of error handling:
import {ErrorStatusText} from '@passageidentity/passage-flex-node'
try {
// function
} catch(error as PassageError) {
switch(error.statusText){
case ErrorStatusText.UserNotFound:
// do whatever
break;
}
}
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.
changed in aceb8fe
…iteral union for PassageError.statusText
b4d5abb
to
aceb8fe
Compare
Fixes:
PassageError
now passes through the specific status code and error information from the API responsesPassageError
Misc:
PassageError.error
has been renamed tocode
to better reflect its value as an error codestatusText
to be more aligned with client SDKs (i.e.invalid_nonce
)PassageError
object can now only be done with the static builder methodsPassageError
without a response error is not async and can therefore be created via the constructor, putting it behind the same static builder method pattern for consistency