-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Reported errors are just string messages #446
Comments
Since the 1.0.0 tag is removed, is this pushed for the long-term, since it would break the API? Is there a possibility to make the |
I’m still not sure how we want to model errors instead of just strings. Changing this would most likely break the backward binary compatibility (but maybe not…), so it would have to go in endpoints-algebra 2.x. Do you think it’s urgent to have it in 1.x? |
For us it would not be urgent, just more convenient. Maybe it is possible to create an experimental algebra post 1.0.0 that does not provide any backwards compatibility guarantees until 2.0.0? I just wonder if we can provide something like that without a lot of duplication with the current algebras. |
I would be interested in knowing more about your use case, maybe that will help us to find the solution 😄 |
Well, not any particular use case right now to be honest. Generally though I like to rely on strongly typed programming instead of stringly typed programming. But there is not big incentive to get something in now. |
I have a particular use case, although probably no time to work on this in the coming days (maybe next week). I want to be able to represent errors in the API like Twitter or Github do - with some error code, messages, maybe some extra information too. In other words, I want custom errors to have lots of potentially nested structure. AFAICT, the methods in /** Convert the ''endpoints'' internal client error type into the [[ClientErrors]] type
* @group operations */
def invalidToClientErrors(invalid: Invalid): ClientErrors
/** Convert the [[ClientErrors]] type into the ''endpoints'' internal client error type
* @group operations */
def clientErrorsToInvalid(clientErrors: ClientErrors): Invalid
/** Convert the ''endpoints'' internal server error type into the [[ServerError]] type
* @group operations */
def throwableToServerError(throwable: Throwable): ServerError
/** Convert the [[ServerError]] type into the ''endpoints'' internal server error type
* @group operations */
def serverErrorToThrowable(serverError: ServerError): Throwable Since I'm not sure what should be changed: |
I think there is everything we need to produce such responses. You can see an example of error responses that are probably similar to what you want to do: https://github.com/julienrf/endpoints-problemdetailserrors/ (and some explanation here) The motivation for having the operation Conversely, the motivation for We could get rid of these operations, but then supporting custom models of errors would be a little bit more complicated: users would also have to customize their client and server interpreters to define what to do with these errors. We’d need to experiment with such a design first. I still think there is everything you need in the current design, though. |
Oh I think I see what you mean now. The functions are not to squeeze a This makes sense - my use case is covered. Thanks for the explanation! |
These links are very helpful. I might have been a bit too early with the stringly typed comment (sorry about that). I have currently used endpoints mostly with the happy path and default errors. |
I am currently looking into this again a bit more. We are using the ujson parsers which could throw an exception if used directly:
However the error is caught and mapped to the message: Invalid JSON document text, which doesn't include anything hinting where the error might be. Can be somehow retrieve if something goes wrong in parsing the JSON using the error of the underlying library instead of an edit: Could we consider using an abstract error type that is made concrete in the interpreters to just be the error model of the underlying library? That way we would never loose any information. |
We’d need to experiment with such solutions. The idea of using an abstract error type could work. Like we do in |
The built-in
Validated
type only report errors asString
messages, making errors hard to process by downstream tools.We could enrich the error model with an optional abstract description of the error:
The proposed error model above is poorly typed. We could have something more precise (at the risk of breaking the ABI more often…).
The text was updated successfully, but these errors were encountered: