vibe-d / vibe.d

Official vibe.d development
MIT License
1.15k stars 284 forks source link

REST server error handling #585

Open extrawurst opened 10 years ago

extrawurst commented 10 years ago

right now the user has no way to control how Exceptions thrown from within a Rest Api method implementation are handled. of course right now one can place a try/catch inside every rest api method to workaround this, but it would be desirable to hook into a somewhat more generalized/central place to return customizeable stuff and do some helpful serverside logging

mihails-strasuns commented 10 years ago

Random idea : define new interface, IErrorHandling, which has Exception callback. Implement it in the same class that implements REST interface. When registering REST class , check if it also implements IErrorHandling and use that callback for exceptions coming from REST methods of it and all its sub-interfaces.

Rationale : encapsulate basic error handling with API it relates to.

extrawurst commented 10 years ago

@Dicebot that sounds like a plan. although it must be a freakishly unique method name to prevent from ever colliding with any sensible REST api method, right ?

mihails-strasuns commented 10 years ago

Collision should not be a problem as you can always override REST method path via UDA.

s-ludwig commented 10 years ago

I'm not convinced of making it part of the interface. After all it's a property of the transport and not of the API itself - the API just throws exceptions, at least on the D side of things. My proposal would be to rather make it either a UDA of the interface (and maybe we could also support it on individual methods), or to pass something as a template parameter to registerRestInterface. The former is nicer because it still keeps things together without mixing API and transport, but it also breaks down if the same API is to be exposed using multiple, different transports (which will probably be rare and even less likely those transports will all be REST). The latter fully decouples the two, but it also requires the same information to match in the server and client instantiations.

whitebyte commented 9 years ago

Hi, any update on this? If no, what is the proper way of handling exception in REST interface? Right now I'm a bit confused, why exceptions thrown from REST are shown to the client and not logged on the server?

jacob-carlborg commented 8 years ago

I agree with @whitebyte.