more faithful error description in openapi spec

pull/4113/head
Rigel Kent 2021-05-13 14:10:04 +02:00
parent e2464d22a5
commit b036eb057e
No known key found for this signature in database
GPG Key ID: 5E53E96A494E452F
1 changed files with 26 additions and 8 deletions

View File

@ -38,30 +38,48 @@ info:
# Errors # Errors
The API uses standard HTTP status codes to indicate the success or failure The API uses standard HTTP status codes to indicate the success or failure
of the API call. The body of the response will be JSON in the following of the API call.
formats.
``` ```
HTTP 1.1 404 Not Found
Content-Type: application/json
{ {
"error": "Account not found" // error debug message "errorCode": 1
"error": "Account not found"
} }
``` ```
Validation errors benefit from a more detailed error type and return the HTTP `400 Bad Request` status code. We provide error codes for [a growing number of cases](https://github.com/Chocobozzz/PeerTube/blob/develop/shared/models/server/server-error-code.enum.ts),
but it is still optional.
### Validation errors
Each parameter is evaluated on its own against a set of rules before the route validator
proceeds with potential testing involving parameter combinations. Errors coming from Validation
errors appear earlier and benefit from a more detailed error type:
``` ```
HTTP 1.1 400 Bad Request
Content-Type: application/json
{ {
"errors": { "errors": {
"id": { // where 'id' is the name of the parameter concerned by the error. "id": { //
"value": "a117eb-c6a9-4756-bb09-2a956239f", // value that triggered the error. "value": "a117eb-c6a9-4756-bb09-2a956239f",
"msg": "Should have an valid id", // error debug message "msg": "Should have a valid id",
"param": "id", "param": "id",
"location": "params" // 'params', 'body', 'header', 'query' or 'cookies' "location": "params"
} }
} }
} }
``` ```
Where `id` is the name of the field concerned by the error, within the route definition.
`errors.<field>.location` can be either 'params', 'body', 'header', 'query' or 'cookies', and
`errors.<field>.value` reports the value that didn't pass validation whose `errors.<field>.msg`
is about.
# Rate limits # Rate limits
We are rate-limiting all endpoints of PeerTube's API. Custom values can be set by administrators: We are rate-limiting all endpoints of PeerTube's API. Custom values can be set by administrators: