I know that I can just cast the result of GetHttpCode () to HttpStatusCode , but I don't like the type conversion. Moreover, the MSDN document does not explicitly state that enumeration values ββare always the exact corresponding http status code.
I feel that GetHttpCode () should just return an HttpStatusCode .
Should I just stop complaining and come up with?
catch(HttpException ex) { switch((HttpStatusCode)ex.GetHttpCode()) { case HttpStatusCode.NotFound: // Do stuff... break; // More cases... } }
EDIT: note that HttpWebResponse.StatusCode is of type HttpStatusCode
It is worth noting that HTTP allows custom status codes, so it does not guarantee that the enumeration will contain the value from your response. For this reason, the API must return an int value instead of trying to use an enumeration.
int
HTTP status codes do not have to come from a fixed list, although this is usually done. Using an enumeration is a convenience. A listing requirement would be incorrect.
The response contains an integer value for the error code. Int is the actual error code. Enumeration allows a "friendly" representation of the error code.
Yes. Or work with the appropriate integer values.
Yes, you have to do it like this. First of all, since the code that you yourself provided protects you from working with any integer values ββor state numbers. So technically it doesnβt matter if the enum values ββmatch the status number values.
Source: https://habr.com/ru/post/1437186/More articles:Creating a PDF file using Zend Framework 2 - pdf-generationCustom sorting by array of strings - c ++Glassfish adds the string "ejb" to the JNDI of a particular EJB mobile phone - javaPowershell open port profile, all (public domain) - powershellDelphi XE - A faster alternative to the System.Pos function - delphiHow to check stdin for CLI using rspec - ruby ββ| fooobar.comSQL query using BLOBS - sqlAdd group to existing MS Office ribbon tab - c #how to test STDIN with RSpec - ruby ββ| fooobar.comjQuery doesn't start in Safari on submit form - jqueryAll Articles