Responsebody of BadRequest (and other errors)
See original GitHub issuewhen trying to get the users and do supply a wrong api-version in the header it always just returns Bad Request and not showing the response body…
The json of the response body should’ve been:
{
"code":400,
"message":"BadRequest: The HTTP resource that matches the request URI 'http://localhost:30002/users' does not support the API version '1.3'.",
"meta":{
"apiVersion":[
"1.3"
]
}
}
When i’m running the request with Curl it does give me the desired output.
When reporting an issue, please provide the following details:
swagger-ui version
Using version: 3.0.8
Swagger file:
swagger: '2.0'
info:
title: Development
description: Api
version: "1.0"
###############################################
# General information #
###############################################
host: localhost:30002
basePath: /
schemes:
- http
produces:
- application/json
consumes:
- application/json
tags:
- name: users
description: Operations for users
###############################################
# Security #
###############################################
securityDefinitions:
implicit:
type: oauth2
description: Secure access using implicit grant
flow: implicit
authorizationUrl: http://localhost:30001/connect/authorize
scopes:
api: Full access to all resources
authorizationCode:
type: oauth2
description: Secure access using authorization grant flow
flow: accessCode
authorizationUrl: http://localhost:30001/connect/authorize
tokenUrl: http://localhost:30001/connect/token
scopes:
api: Full access to all resources
security:
- implicit:
- api
- authorizationCode:
- api
###############################################
# Parameters #
###############################################
parameters:
apiVersion:
in: header
name: api-version
type: string
format: string
description: Api version to use
required: false
default: '1.0'
###############################################
# Responses #
###############################################
responses:
error:
description: An error has occured while handling the request. Check the content of the message for the error details.
schema:
$ref: '#/definitions/error'
###############################################
# Definitions #
###############################################
definitions:
user:
type: object
description: Defines a user. This can be a driver, backoffice employee, etc.
properties:
id:
type: integer
format: int32
description: Uniquely identifies the user.
key:
type: string
description: Uniquely identifies the user to the ERP system.
name:
type: string
description: The display name of the user.
email:
type: string
description: The e-mail address of the user.
error:
type: object
description: Describes the error that occured during the request.
properties:
code:
type: string
description: The error code that occured.
message:
type: string
description: A user readable message that describes the error in detail for the developer.
meta:
type: object
description: |
Contains more information about the error message. For example when a validation error occurs, this field describes the fields that were invalid and the validation error that occured. The content of this object can vary based on the type of error.
required:
- code
- message
###############################################
# Paths #
###############################################
paths:
/users:
parameters:
- $ref: '#/parameters/apiVersion'
get:
tags:
- users
summary: Get all the available users.
description: Returns all the available users connected to the company.
responses:
200:
description: Successful.
schema:
type: array
items:
$ref: '#/definitions/user'
default:
$ref: '#/responses/error'
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Rest error message in HTTP Header or Response Body?
My question is where is the recommended place to put the reason/description/cause of the error? Does it make more sense for the REST...
Read more >Problem Details - The right way to specify errors in Web API ...
Many people have different designs for specifying the errors in the API response - some just return status code without any response message ......
Read more >Handling errors in ASP.NET Core Web API - DevTrends
This post looks at the best ways to handle exceptions, validation and other invalid requests such as 404s in ASP.NET Core Web API...
Read more >Problem Details for Better REST HTTP API Errors - CodeOpinion
This first example is using a Status Code of 400 Bad Request, which is good. They provide a response body that has a...
Read more >Consistent error responses in ASP.NET Core Web APIs
Now we need to take care of errors. Since returning an HTTP status code with an empty response body is almost always not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Same issue: 3.x:
2.x:

I want it shows the response body no matter what status code it is, otherwise I have to read the response body in Chrome Web Developer Tools:
I love the fact that #3041 is created later and this is marked as duplicate hahah 😂 The first explains it better though + providing a sample 👍