Created
April 5, 2012 16:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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