Error handling server/client ?
michaelsauter opened this issue · comments
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!
Hey @michaelsauter thanks for raising this. You're right, we will change that to just call OnErr
.
@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 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.