From b036eb057efda11259400d3d204c1e48c9755de8 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 13 May 2021 14:10:04 +0200 Subject: [PATCH] more faithful error description in openapi spec --- support/doc/api/openapi.yaml | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml index f54df1dd0..6e82864a0 100644 --- a/support/doc/api/openapi.yaml +++ b/support/doc/api/openapi.yaml @@ -38,30 +38,48 @@ info: # Errors 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 - formats. + of the API call. ``` + 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": { - "id": { // where 'id' is the name of the parameter concerned by the error. - "value": "a117eb-c6a9-4756-bb09-2a956239f", // value that triggered the error. - "msg": "Should have an valid id", // error debug message + "id": { // + "value": "a117eb-c6a9-4756-bb09-2a956239f", + "msg": "Should have a valid 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..location` can be either 'params', 'body', 'header', 'query' or 'cookies', and + `errors..value` reports the value that didn't pass validation whose `errors..msg` + is about. + # Rate limits We are rate-limiting all endpoints of PeerTube's API. Custom values can be set by administrators: