public Task HandleExceptionAsync(HttpContext context, Exception exception) { //Log exception here string result = JsonConvert.SerializeObject(Envelope.Error(exception.Message)); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(context.Response.WriteAsync(result)); }
//single processor for all exceptions private Task HandleExceptionAsync(HttpContext context, Exception exception) { //log the exception here //serialize it //string result = JsonConvert.SerializeObject(new { error = exception.Message }); string result = JsonConvert.SerializeObject(Envelope.Error(exception.Message)); //fill the statuscode of the response context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.ContentType = "application/json"; //write the json string in the response return(context.Response.WriteAsync(result)); }
protected IActionResult Error(string errorMessage) { return(BadRequest(Envelope.Error(errorMessage))); }