It is rather cumbersome to extract data from error response body:
class Error
{
... error data ...
}
try
{
... do Ramone web stuff ...
}
catch (WebException ex)
{
if (ex.Response is HttpWebResponse)
{
HttpWebResponse response = (HttpWebResponse)ex.Response;
if (response.ContentType == "... prefered error response format ...")
{
try
{
using (Response<Error> r = new Response<Error>(response, Session, 0))
{
Error err = r.Body;
... do stuff with error data ...
}
}
catch (Exception ex2)
{
... decoding failed! Now what? ...
}
}
}
else
{
... nothing known in the response body ...
}
}
Can it be done easier? Like this:
class Error
{
... error data ...
}
try
{
... do Ramone web stuff ...
}
catch (WebException ex)
{
using (var response = Session.ErrorResponse<Error>(ex))
{
Error err = response.Body;
... do stuff with error data ...
}
// OR
Session.TryHandleError<Error>(ex,
err =>
{
... do stuff with error data ...
});
}
It is rather cumbersome to extract data from error response body:
Can it be done easier? Like this: