Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Break when status code has been handled #1668

Merged
merged 2 commits into from
Aug 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/Nancy/NancyEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,23 @@ private void CheckStatusCodeHandler(NancyContext context)
return;
}

foreach (var statusCodeHandler in this.statusCodeHandlers)
var handlers = this.statusCodeHandlers
.Where(x => x.HandlesStatusCode(context.Response.StatusCode, context))
.ToList();

var defaultHandler = handlers
.FirstOrDefault(x => x is DefaultStatusCodeHandler);

var customHandler = handlers
.FirstOrDefault(x => !(x is DefaultStatusCodeHandler));

var handler = customHandler ?? defaultHandler;
if (handler == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will never be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the DefaultStatusCodeHandler has been removed, it could be null. Better safe than sorry 😉

{
if (statusCodeHandler.HandlesStatusCode(context.Response.StatusCode, context))
{
statusCodeHandler.Handle(context.Response.StatusCode, context);
}
return;
}

handler.Handle(context.Response.StatusCode, context);
}

private Task<NancyContext> InvokeRequestLifeCycle(NancyContext context, CancellationToken cancellationToken, IPipelines pipelines)
Expand Down