Skip to content

Instantly share code, notes, and snippets.

@2garryn
Created February 19, 2019 18:06
Show Gist options
  • Save 2garryn/a71984ee55d13e5e79ffa230ecbff73c to your computer and use it in GitHub Desktop.
Save 2garryn/a71984ee55d13e5e79ffa230ecbff73c to your computer and use it in GitHub Desktop.
public async Task InvokeAsync(HttpContext httpContext)
{
httpContext.Response.ContentType = "application/json";
httpContext.Response.StatusCode = 200;
try
{
await _next(httpContext);
}
catch (InternalException.Error em)
{
await httpContext.Response.WriteAsync(ExceptionToString(em));
}
}
private string ExceptionToString(InternalException.Error exp)
{
var reply = new
{
isError = true,
code = exp.ErrorCode,
message = exp.ErrorMessage
};
return JsonConvert.SerializeObject(reply);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment