I’ve recently been using Nancy to build an API, and have found it a pleasure to work with.
I do have one minor complaint though: it’s cutesy default error page…
I understand the motivation, and I can see how it helps with the “super-duper-happy-path”. But, when developing an API in a corporate environment, it’s frankly a bit embarrassing.
I want my YSOD back! The good news is, you can, with a little bit of work.
public class YsodErrorHandler : IErrorHandler { public bool HandlesStatusCode(HttpStatusCode statusCode) { return statusCode == HttpStatusCode.InternalServerError; } public void Handle(HttpStatusCode statusCode, NancyContext context) { object errorObject; context.Items.TryGetValue(NancyEngine.ERROR_EXCEPTION, out errorObject); var exception = errorObject as Exception; if (exception != null) { throw exception; } } }
Et voila!
(Caveat: this will only work with 0.10.0, previous versions don’t provide the exception object). The best bit is, you don’t even have to register the error handler, Nancy will scan for it!
Does unfortunately not work with latest version. ErrorObject is always null.
Seems to work for me, with Nancy 0.15.1.
https://github.com/grahamrhay/Nancy-YSOD
Oh, thanks for letting me know.