WebAPI - Returning HTTP status code without throwing or changing method signature?
-
@blakeyrat said in WebAPI - Returning HTTP status code without throwing or changing method signature?:
(Some pedantic dickweed is gonna come in here and imagine some obscure-ass controller that succeeds 100% of the time, and to that person: fuck you in advance.)
amazing, this really made me chuckle
-
@tsaukpaetra said in WebAPI - Returning HTTP status code without throwing or changing method signature?:
Besides, the standard way to tell C# that your method failed is to... throw an exception, which is exactly one of the things you're complaining about.
That's great, but very few of the HTTP statuses can be mapped to exceptions. Not having permission to do something isn't exceptional in any way, nothing in the 300 series is, etc. Only 5xx I'd call exceptions.
-
@blakeyrat Most of 400 is fairly exceptional.
200 and 300 series, though...
-
@blakeyrat said in WebAPI - Returning HTTP status code without throwing or changing method signature?:
Feel free to post the 27 ways this code is stupid and wrong.
Official naming conventions say that abbreviations longer than two characters should not be all caps. The namespace should be
Xxx.Platform.Api
.
-
@blakeyrat said in WebAPI - Returning HTTP status code without throwing or changing method signature?:
@tsaukpaetra said in WebAPI - Returning HTTP status code without throwing or changing method signature?:
Besides, the standard way to tell C# that your method failed is to... throw an exception, which is exactly one of the things you're complaining about.
That's great, but very few of the HTTP statuses can be mapped to exceptions. Not having permission to do something isn't exceptional in any way, nothing in the 300 series is, etc. Only 5xx I'd call exceptions.
So, since you are using the HTTP features, USE THE IHTTPRESULT.
It's really not all that difficult, really.