Skip to content

Commit

Permalink
Demonstrate OnError not working in Release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Young committed Sep 8, 2015
1 parent 97b40c6 commit 5a318b5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
26 changes: 26 additions & 0 deletions src/Nancy.Demo.Razor.Localization/DemoBootstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace Nancy.Demo.Razor.Localization
{
using Bootstrapper;
using Nancy.ErrorHandling;
using Nancy.Responses;
using Nancy.TinyIoc;

public class DemoBootstrapper : DefaultNancyBootstrapper
{
Expand All @@ -11,5 +14,28 @@ protected override NancyInternalConfiguration InternalConfiguration
return NancyInternalConfiguration.WithOverrides(x => x.ResourceAssemblyProvider = typeof(CustomResourceAssemblyProvider));
}
}

protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
pipelines.OnError += (ctx, ex) =>
{
ctx.Items["ON_ERROR"] = "value from OnError";
return null;
};
}
}

public class StatusCodeHandler : IStatusCodeHandler
{
public bool HandlesStatusCode(HttpStatusCode statusCode, NancyContext context)
{
return true;
}

public void Handle(HttpStatusCode statusCode, NancyContext context)
{
context.Response = new TextResponse(statusCode, (string)context.Items["ON_ERROR"]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<RootNamespace>Nancy.Demo.Razor.Localization</RootNamespace>
<AssemblyName>Nancy.Demo.Razor.Localization</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<UseIISExpress>true</UseIISExpress>
<UseIISExpress>false</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
Expand Down Expand Up @@ -136,16 +136,7 @@
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>56029</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:61703/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
<SaveServerSettingsInUserFile>True</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
Expand Down
6 changes: 6 additions & 0 deletions src/Nancy.Demo.Razor.Localization/Views/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
<br />
{ "en-US", "Howdy Partner" }
</p>

@{
var nums = new int[0];
}

@nums[1]

0 comments on commit 5a318b5

Please sign in to comment.