Skip to content
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

Typed Error Exceptions #39

Open
woodhull opened this issue Sep 24, 2020 · 3 comments
Open

Typed Error Exceptions #39

woodhull opened this issue Sep 24, 2020 · 3 comments

Comments

@woodhull
Copy link
Collaborator

We have a set of cases in our app where we have special handling for different errors returned by the ngpvan api.

We have thought about extending the exception typing in the gem to be aware of various more finely typed sorts of errors that come back from the api (often data validation issues). we could then catch those typed exceptions in our app.

Would that be a welcome improvement? There are a few sorts of errors that are recoverable on our side and typing the exceptions would help us cleanup some code on our side.

@lavaturtle
Copy link
Contributor

Some examples of the types of errors we're talking about: "Phone number is invalid", or "Person must be a valid accessible contact".
Obviously one wrinkle here is that sometimes a response has more than one validation error in it.

@woodhull
Copy link
Collaborator Author

Could use a module exception tagging approach like https://gist.github.com/garethrees/10373806

@christopherstyles
Copy link
Owner

Interesting!

In the case of input validation, the API returns a 400: Bad Request status with an INVALID_PARAMETER code. I think all validation errors have the same code, so I guess I’m not entirely sure how you would type these exceptions more specifically when their codes are the same?

Were you thinking of extending, say, the NgpVan::BadRequest class with variants that you would derive by doing some x, y, z logic on the error.text, then returning a more specific exception? As @lavaturtle mentioned, there could be multiple errors so that might be problematic.

It’s quite possible I’m missing something obvious though, would love to hear more 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants