protected IHttpActionResult GetErrorResult(IdentityResult result) { if (result == null) { return(InternalServerError()); } if (result.Succeeded) { return(null); } if (result.Errors != null) { foreach (var error in result.Errors) { ModelState.AddModelError("Error", error); } } if (ModelState.IsValid) { /* * Ошибки ModelState недоступны для отправки, поэтому просто возвращаем пустой BadRequest. */ return(BadRequest()); } var modelState = new ApiResourceValidationErrorWrapper(ModelState); var json = JsonConvert.SerializeObject(modelState); return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(json, Encoding.UTF8, "application/json") })); }
protected IHttpActionResult GetErrorFromModel(string model, string text) { ModelState.AddModelError(model, text); var modelState = new ApiResourceValidationErrorWrapper(ModelState); var json = JsonConvert.SerializeObject(modelState); return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(json, Encoding.UTF8, "application/json") })); }