Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created April 5, 2012 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecodejunkie/2312362 to your computer and use it in GitHub Desktop.
Save thecodejunkie/2312362 to your computer and use it in GitHub Desktop.
Using the error pipeline to capture and handle exception in a Nancy application
public class ErrorHandler : IStartup
{
public IEnumerable<TypeRegistration> TypeRegistrations
{
get { return null; }
}
public IEnumerable<CollectionTypeRegistration> CollectionTypeRegistrations
{
get { return null; }
}
public IEnumerable<InstanceRegistration> InstanceRegistrations
{
get { return null; }
}
public void Initialize(IPipelines pipelines)
{
pipelines.OnError += (context, exception) => {
Debug.WriteLine("The following exception was captured: " + exception.ToString());
return HttpStatusCode.InternalServerError;
};
}
}
public class Home : NancyModule
{
public Home()
{
Get["/"] = parameters => {
return string.Format(
"Running, click <a href='{0}'>here</a> to throw an exception",
this.Context.ToFullPath("~/exception"));
};
Get["/exception"] = parameters => {
throw new NotImplementedException();
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment