Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Net HttpStatusCode class does not have code 422

Is there a way to handle http status code 422 gracefully. I am looking for the best practice here. I know that HttpStatusCode is an enum so what i tried is this,

HttpStatusCode Unprocessable = (HttpStatusCode)422; if (Response == (HttpStatusCode)422) 

but does not allow me to compare it. Am i doing something wrong here?

Whats the best possible way to add this status code at runtime.

like image 568
golldy Avatar asked Apr 21 '15 03:04

golldy


1 Answers

I was using RestSharp which returns the server response status code in a property of type HttStatusCode and I needed to check for a 422 response myself but the of course the type doesn't include it. Fortunately I was still able to test using the following:

if(response.StatusCode == (HttpStatusCode)422) {     // Do my stuff.. } 
like image 86
Nick Gotch Avatar answered Sep 22 '22 04:09

Nick Gotch