c# - How do I get StatusCode from HttpRequestException? -


i'm missing obvious here.

i'm using httpclient throws httprequestexception contains statuscode in message string.

how can access statuscode?


edit: more info, wrote question in rush.

i'm using httpclient access api within webapi project. yes, know why i'm calling ensuresuccessstatuscode(). want propagate errors downstream such 404 , 403.

all wanted consistently transform httprequestexception httpresponseexception using custom exceptionfilterattribute.

unfortunately, httprequestexception not carry info use besides message. hoping uncover statuscode in raw (int or enum) form.

looks can either:

  1. use message switch status code (bleh)
  2. or create version of ensuresuccessstatuscode , throw exception that's usable.

status code passed part of string httprequestexception cannot recover such exceptions alone.

the design of system.net.http requires access httpresponsemessage.statuscode instead of waiting exception.

http://msdn.microsoft.com/en-us/library/system.net.http.httpresponsemessage(v=vs.110).aspx

if following the microsoft guide, make sure understand why asks call httpresponsemessage.ensuresucessstatuscode. if don't call function, there should no exception.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -