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

How to use the error file in the custom schema? #77

Closed
jimmybrenes opened this issue Mar 8, 2022 · 1 comment
Closed

How to use the error file in the custom schema? #77

jimmybrenes opened this issue Mar 8, 2022 · 1 comment
Assignees

Comments

@jimmybrenes
Copy link

jimmybrenes commented Mar 8, 2022

Hello,

I would like to know how to use the error.rs of the custom schema, specifically the function of the implementations

*impl std::fmt::Display for Error
impl<'r> Responder<'r, 'static> for Error
impl From<rocket::serde::json::Error<'_>> for Error

Also, I want to know if it is possible to choose which errors each endpoint returns, because as I have it now, the errors are shown for all the endpoints.

Thanks!

@ralpha
Copy link
Collaborator

ralpha commented Mar 11, 2022

In this file (you most likely are referring to) https://github.com/GREsau/okapi/blob/master/examples/custom_schema/src/error.rs
you can find how to implement an Error. This is just 1 struct. In the docs it will be stated that this only returns 4 different responses. (400, 404, 422 and 500)

If you want your own error just copy that code and change the errors you don't/do need. (remove/add some)
If you want 2 endpoints to have different responses you can do that by creating to structs. Lets say ServerError and FileError.
We can just add the errors we want to each endpoint by changing the error type it will return.

Also take a look at these links:
Related issue: #34
An older project (that still uses older version of Okapi):
APIErrorNoContent returns 204, 400, 404 and 500.
APIErrorNotModified returns 304, 400, 404 and 500.

Hope this helps you, if you have more specific questions, just ask.

@ralpha ralpha self-assigned this Jun 5, 2022
@ralpha ralpha closed this as completed Jun 5, 2022
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

2 participants