hoplon / castra

HTTP remote procedure call handler for Clojure.
170 stars 25 forks source link

Return HTTP 500 error status when exception occurs #26

Closed juergenhoetzel closed 6 years ago

juergenhoetzel commented 7 years ago

Currently middleware return status 200 even when exception occurs:

juergen@samson:~ → curl -X POST -d '["~$modern-cljs.core/test2",12,2,3]' -v -H "Content-Type: application/json"  -H "x-castra-csrf: true" http://localhost:8888/test1
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8888 (#0)
> POST /test1 HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/7.54.1
> Accept: */*
> Content-Type: application/json
> x-castra-csrf: true
> Content-Length: 35
> 
* upload completely sent off: 35 out of 35 bytes
< HTTP/1.1 200 OK
< Date: Sat, 22 Jul 2017 11:53:29 GMT
< X-Castra-Tunnel: transit
< Content-Type: application/json
< Content-Length: 3492
< Server: Jetty(9.2.10.v20150310)
< 
["^ ","~:error",["^ ","~:message","Server error.","~:data",["^ ","~:castra.core/exception",true],
...

Using this commit:


juergen@samson:~/tmp/castra → curl -X POST -d '["~$modern-cljs.core/test2",12,2,3]' -v -H "Content-Type: application/json"  -H "x-castra-csrf: true" http://localhost:8888/test1
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8888 (#0)
> POST /test1 HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/7.54.1
> Accept: */*
> Content-Type: application/json
> x-castra-csrf: true
> Content-Length: 35
> 
* upload completely sent off: 35 out of 35 bytes
< HTTP/1.1 500 Server Error
< Date: Sat, 22 Jul 2017 13:03:13 GMT
< X-Castra-Tunnel: transit
< Content-Type: application/json;charset=utf-8
< Content-Length: 3330
< Server: Jetty(9.2.10.v20150310)
< 
["^ ","~:error",["^ ","~:message","Server error.","~:data",["^ ","~:castra.core/exception",true],
jumblerg commented 6 years ago

this is by design: the exception is tunneled back to the client where it can be handled remotely. the 200 indicates that the transport of this error was successful.

juergenhoetzel commented 6 years ago

this is by design: the exception is tunneled back to the client where it can be handled remotely. the 200 indicates that the transport of this error was successful.

Thanks for the feedback. Makes sense.

jumblerg commented 6 years ago

thanks for the report! there was a point, as i recall, that the exception was tunneled with the status code corresponding to the error itself, but i believe this caused some problems.