Created
November 27, 2012 16:02
-
-
Save jmarnold/4155080 to your computer and use it in GitHub Desktop.
Ajax continuation failures
This file contains hidden or 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 static AjaxContinuation SystemFailure(this AjaxContinuation continuation, Exception exception) | |
{ | |
continuation.Success = false; | |
continuation[EXCEPTION] = new AjaxException | |
{ | |
type = exception.GetType().Name, | |
message = exception.Message, | |
stacktrace = exception.StackTrace | |
}; | |
return continuation; | |
} |
This file contains hidden or 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 AjaxException | |
{ | |
public string type { get; set; } | |
public string message { get; set; } | |
public string stacktrace { get; set; } | |
} |
This file contains hidden or 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 ReportSystemFailure : IActionBehavior | |
{ | |
private readonly IActionBehavior _inner; | |
private readonly IJsonWriter _writer; | |
private readonly ILogger _logger; | |
public ReportSystemFailure(IActionBehavior inner, IJsonWriter writer, ILogger logger) | |
{ | |
_inner = inner; | |
_writer = writer; | |
_logger = logger; | |
} | |
public void Invoke() | |
{ | |
try | |
{ | |
_inner.Invoke(); | |
} | |
catch (Exception exc) | |
{ | |
_logger.Error(exc.Message, exc); | |
var continuation = new AjaxContinuation(); | |
continuation.SystemFailure(exc); | |
_writer.Write(continuation.ToDictionary(), MimeType.Json.ToString()); | |
} | |
} | |
public void InvokePartial() | |
{ | |
Invoke(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment