You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like when the internal works api (api.workos.com) throws an error you just return it.
For example the api authenticateWithCode can throw an error for email verification, but the types for the errors are not in this library.
Can you guys please add a custom error type and interfaces for your errors?
Here is how I need to handle it now:
workos.userManagement.authenticateWithCode({ clientId, code }).catch((error)=>{// The error code should be as described here:// https://workos.com/docs/reference/user-management/authentication-errorsif(error.code==="email_verification_required"){context.set.status=401;// unauthorizedreturnerror;}// Additional if clauses for other errors.// Else let the error bubble upthrowerror;});
Now I have two problems, a) my API is not typed unless I create types for all the errors manually, and b) I need to write code to handle all the workOS errors to separate them from server errors, as can be seen I the if clause.
If you were to use custom error classes then problem "a" would be solved, and if you add types then problem "b" would be solved. Or better yet you could create both and type the classes so that we get the best of bth worlds.
My code would then look like this:
workos.userManagement.authenticateWithCode({ clientId, code }).catch((error)=>{if(errorinstanceofAuthenticationError){// handle works errors}// Else let the error bubble upthrowerror;});
And the error will be typed!
The text was updated successfully, but these errors were encountered:
It seems like when the internal works api (api.workos.com) throws an error you just return it.
For example the api
authenticateWithCode
can throw an error for email verification, but the types for the errors are not in this library.Can you guys please add a custom error type and interfaces for your errors?
Here is how I need to handle it now:
Now I have two problems, a) my API is not typed unless I create types for all the errors manually, and b) I need to write code to handle all the workOS errors to separate them from server errors, as can be seen I the
if
clause.If you were to use custom error classes then problem "a" would be solved, and if you add types then problem "b" would be solved. Or better yet you could create both and type the classes so that we get the best of bth worlds.
My code would then look like this:
And the error will be typed!
The text was updated successfully, but these errors were encountered: