private static void ConfigureHttpStatusToOperationOutcomeMiddleware(IApplicationBuilder applicationBuilder, HttpStatusToOperationOutcomeMiddlewareOptions options) { var availableAccept = string.Join(", ", applicationBuilder.ApplicationServices.GetServices <IOutputFormatter>().OfType <TextOutputFormatter>().SelectMany(e => e.SupportedMediaTypes).Select(t => $"\"{t}\"")); var availableContentType = string.Join(", ", applicationBuilder.ApplicationServices.GetServices <IInputFormatter>().OfType <TextInputFormatter>().SelectMany(e => e.SupportedMediaTypes).Select(t => $"\"{t}\"")); var acceptErrorMesage = $"Не верные параметры запроса. Сервер поддерживает форматы: {availableAccept}. Сервер поддерживает поддерживает только кодировку UTF-8"; var contentTypeErrorMesage = $"Не верные параметры запроса. Сервер поддерживает кодировку UTF-8 и форматы: {availableContentType}."; options.ForException <FhirHttpResponseException>().UseHandler(exception => new OperationOutcomeResultContext(exception.StatusCode, exception.OperationOutcome)); options.ForException <ValidationException>().UseHandler(exception => new OperationOutcomeResultContext((HttpStatusCode)400, OperationOutcomeExtensions.GetOperationOutcome().AddFailures(exception.Errors).AddException(exception))); options.ForException <System.ComponentModel.DataAnnotations.ValidationException>().UseHandler(exception => new OperationOutcomeResultContext((HttpStatusCode)400, OperationOutcomeExtensions.GetOperationOutcome().AddError(exception.ValidationResult.ErrorMessage))); options.ForException <FormatException>().UseHandler(exception => new OperationOutcomeResultContext((HttpStatusCode)422, OperationOutcomeExtensions.GetOperationOutcome().AddError("Невозможно выполнить синтаксический разбор ресурса, либо он не проходит базовые правила валидации FHIR").AddException(exception))); options.ForStatusCode(HttpStatusCode.NotAcceptable).UseHandler(code => new OperationOutcomeResultContext(code, OperationOutcomeExtensions.GetOperationOutcome().AddError(acceptErrorMesage))); options.ForStatusCode(HttpStatusCode.UnsupportedMediaType).UseHandler(code => new OperationOutcomeResultContext(code, OperationOutcomeExtensions.GetOperationOutcome().AddError(contentTypeErrorMesage))); options.ForStatusCode(HttpStatusCode.Forbidden).UseHandler(code => new OperationOutcomeResultContext(code, OperationOutcomeExtensions.GetOperationOutcome().AddError("Нет прав на доступ к запрашиваемому ресурсу"))); options.ForStatusCode(HttpStatusCode.Unauthorized).UseHandler(code => new OperationOutcomeResultContext(code, OperationOutcomeExtensions.GetOperationOutcome().AddError("Необходимо пройти аутентификацию"))); }
public void IssueSeverity_Is_Fatal_When_HttpStatusCode_Is_InternalServerError_Test() { Assert.AreEqual(OperationOutcome.IssueSeverity.Fatal, OperationOutcomeExtensions.IssueSeverityOf(System.Net.HttpStatusCode.InternalServerError)); }
public void IssueSeverity_Is_Warning_When_HttpStatusCode_Is_MovedPermanently_Test() { Assert.AreEqual(OperationOutcome.IssueSeverity.Warning, OperationOutcomeExtensions.IssueSeverityOf(System.Net.HttpStatusCode.MovedPermanently)); }
public void IssueSeverity_Is_Error_When_HttpStatusCode_Is_BadRequest_Test() { Assert.AreEqual(OperationOutcome.IssueSeverity.Error, OperationOutcomeExtensions.IssueSeverityOf(System.Net.HttpStatusCode.BadRequest)); }
public void IssueSeverity_Is_Information_When_HttpStatusCode_Is_Created_Test() { Assert.AreEqual(OperationOutcome.IssueSeverity.Information, OperationOutcomeExtensions.IssueSeverityOf(System.Net.HttpStatusCode.Created)); }