Skip to content

Error handling server/client ? #23

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

Closed
michaelsauter opened this issue Sep 28, 2020 · 3 comments
Closed

Error handling server/client ? #23

michaelsauter opened this issue Sep 28, 2020 · 3 comments

Comments

@michaelsauter
Copy link

First, thanks for this tool! I really like it so far.

I'm wondering a bit though how errors are supposed to be handled? Maybe I'm missing something, but what I'm seeing is this:

If I return a non-nil error from one of the service endpoints, a 500 is returned to the client with the body being the error message (https://github.com/pacedotdev/oto/blob/master/otohttp/templates/server.go.plush#L46-L47). On the client side, the response is assumed to be JSON though (https://github.com/pacedotdev/oto/blob/master/otohttp/templates/client.ts.plush#L38), which leads to a JS error like SyntaxError: Unexpected token c in JSON at position 0. So out-of-the-box that seems a bit broken ... and I'm a bit confused why the "service endpoint error" is not simply handled with s.server.OnErr(w, r, err), like in the other error cases? Would be great if you could shed some light on this!

@matryer
Copy link
Contributor

matryer commented Sep 30, 2020

Hey @michaelsauter thanks for raising this. You're right, we will change that to just call OnErr.

matryer added a commit that referenced this issue Sep 30, 2020

Verified

This commit was signed with the committer’s verified signature.
jviide Joachim Viide
@matryer
Copy link
Contributor

matryer commented Sep 30, 2020

@michaelsauter that's fixed now. Remember, you are free to copy and make any changes you like to the templates. This is the easiest way to customise Oto.

@matryer matryer closed this as completed Sep 30, 2020
@michaelsauter
Copy link
Author

@matryer Thanks! Yes I changed the template to use OnErr, but I wasn't sure if there was a specific reason NOT to do this ... thanks for clarifying.

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