--
You received this message because you are subscribed to the Google Groups "JSON-RPC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to json-rpc+u...@googlegroups.com.
To post to this group, send email to json...@googlegroups.com.
Visit this group at https://groups.google.com/group/json-rpc.
For more options, visit https://groups.google.com/d/optout.
It should,
You should configure all your error systems so to give an Error object by setting the handler files, you can look at https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04 to see how to configure error handler pages in NGinX.
So the only error that does not also give an error object is a server offline error AKA a Connection Timeout, and it's for the reason of what if the client ignores the status you want to give them an error that they can still parse with a JSON decode.
ok. what if on my sever some urls are jsonrpc endpoints, and some other - REST endpoints (both with same authentication). Should I manintain a list of JSONRPC URL in nginx to show JSONRPC error page to jsonrpc endpoints only?
Another case - SSL connection and bad certificate.
Or another case - In JSONRPC over unix sockets authentication would be unix file permissions, and if permission to socket is denied, there will be unix errno "permission denied" and no JSONRPC answer.
Victor,Another way you might think about this is that yes, as you mentioned the HTTP status code is a transport level concern, while the JSON-RPC error is an application logic concern. Your application logic could probably function just fine regardless of what status code you used as long as you return JSON-RPC responses.
However, returning correct status codes will help that transport layer function correctly.
For example, intermediate HTTP caching servers and other middleware will probably never cache a 403 response, but might cache 200 responses.In nginx you should be able to define different error pages for each route, likelocation /rpc {error_page ......}location /rest {error_page ......}
And as Martin discussed, SSL errors and unix sockets aren't really JSON-RPC concerns since no connection would be established and therefore no JSON-RPC requests or responses would be sent.
pros: It's easier to write application, because it does not have to have extra "if status==401" branch to handle transport level error.
cons: need inject into nginx proxy error_page for each rpc endpoint. i.e. need to keep a list of rpc endpointsin nginx, which is above in stack of transport. I think it's a https://en.wikipedia.org/wiki/Leaky_abstraction becausenginx should know nothing about internals of upstream server.
User_Authentication_Exception implements JSONRPC_Exception;
function handle_user_request(){
if user_logged_in eq true then
constuct user response object
return user response object;
else
throw User_Authentication_Exception;
}
try{
handle_user_request();
}catch( User_Authentication_Exception jx){ // user not authed exception
// output the given Error (jx) for the user not authed request
}catch(JSONRPC_Exception jx){ // unknow json error caught
// output the given Error (jx) for the Exception request
}catch(Exeption e){ // unhandled exception
// create and output an Error for a server application error
}
That part is related to why I think that (2) cons is not a problem at all.
Client application anyway should have centralized place where it creates connection to server and where it handles errors, because there are cases like bad SSL, unix socket errors, and
broken connection. The same place would be used for this one "if 401" branch. So on client side there will be "if 401" in only one place.
That is why (2) "cons" is much better than (1) "cons".
pros: It's easier to write application, because it does not have to have extra "if status==401" branch to handle transport level error.This is not a transport level error this a transmission of a data through the transport layer was incorrect for this request, the JSON body then tells why the error occurred much like when you do it in a Web Browser the 401 status is sent then the HTML body explaining why it failed.
cons: need inject into nginx proxy error_page for each rpc endpoint. i.e. need to keep a list of rpc endpointsin nginx, which is above in stack of transport. I think it's a https://en.wikipedia.org/wiki/Leaky_abstraction becausenginx should know nothing about internals of upstream server.No, you can do all error handling inside your server-side application if it was architected to support this (see E.G below). this would mean you don't require custom error handlers for most errors if not all. and
you also need to separate endpoints for directories
a web server works with directories you can then effectively hack the server into going this file is actually hear this is rewriting. but the server core does not understand that so your rules for your errors are on