Иногда это происходит может вернуть JSON в формате, соответствующем RFC 7807 (что является ожидаемым сценарием). Но он также может возвращать простой текст или даже другой формат, который кажется просто десериализованным исключением.
У меня есть несколько примеров каждого поведения:
Код: Выделить всё
var response = await _mediator.Send(request);
if (!response.Succeeded)
{
// not return in the RFC 7807 format, but the "Error" content is converted to a JSON
return BadRequest(response.Error);
// returns the RFC 7807 format
return BadRequest();
// returns a plain text with the message "Hello"
return BadRequest("Hello");
// returns in the RFC 7807 format
return BadRequest(new ProblemDetails
{
Status = StatusCodes.Status400BadRequest,
Title = "Bad Request",
Detail = response.Error.Message,
Type = "https://tools.ietf.org/html/rfc7231#section-6.5.1",
});
}
return response.ToHttpResult();
Подробнее здесь: https://stackoverflow.com/questions/793 ... et-project
Мобильная версия