Created
November 6, 2012 13:19
-
-
Save benfoster/4024709 to your computer and use it in GitHub Desktop.
Deserializing HttpError
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 class HttpErrorExtensions | |
{ | |
public static ModelStateDictionary GetModelState(this HttpError httpError) | |
{ | |
Ensure.Argument.NotNull(httpError, "httpError"); | |
object serialized; | |
if (httpError.TryGetValue("ModelState", out serialized)) | |
{ | |
var modelState = new ModelStateDictionary(); | |
var errors = (HttpError)httpError["ModelState"]; | |
foreach (var error in errors) | |
{ | |
foreach (var message in error.Value as string[]) | |
{ | |
modelState.AddModelError(error.Key, message); | |
} | |
} | |
return modelState; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment