From c1295bfb3ab27f85dd1a9f5f30ac85746df10ab6 Mon Sep 17 00:00:00 2001 From: Alexey Kondratov Date: Fri, 1 Dec 2023 18:19:55 +0100 Subject: [PATCH] [compute_ctl] User correct HTTP code in the /configure errors (#6017) It was using `PRECONDITION_FAILED` for errors during `ComputeSpec` to `ParsedSpec` conversion, but this disobeys the OpenAPI spec [1] and correct code should be `BAD_REQUEST` for any spec processing errors. While on it, I also noticed that `compute_ctl` OpenAPI spec has an invalid format and fixed it. [1] https://github.com/neondatabase/neon/blob/fd81945a60dff25fea65a50f2c8cd6e4c955fba4/compute_tools/src/http/openapi_spec.yaml#L119-L120 --- compute_tools/src/http/api.rs | 2 +- compute_tools/src/http/openapi_spec.yaml | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compute_tools/src/http/api.rs b/compute_tools/src/http/api.rs index ef6ca6eee3..fa2c4cff28 100644 --- a/compute_tools/src/http/api.rs +++ b/compute_tools/src/http/api.rs @@ -227,7 +227,7 @@ async fn handle_configure_request( let parsed_spec = match ParsedSpec::try_from(spec) { Ok(ps) => ps, - Err(msg) => return Err((msg, StatusCode::PRECONDITION_FAILED)), + Err(msg) => return Err((msg, StatusCode::BAD_REQUEST)), }; // XXX: wrap state update under lock in code blocks. Otherwise, diff --git a/compute_tools/src/http/openapi_spec.yaml b/compute_tools/src/http/openapi_spec.yaml index dc26cc63eb..cedc6ece8f 100644 --- a/compute_tools/src/http/openapi_spec.yaml +++ b/compute_tools/src/http/openapi_spec.yaml @@ -156,17 +156,17 @@ paths: description: Error text or 'OK' if download succeeded. example: "OK" 400: - description: Request is invalid. - content: - application/json: - schema: - $ref: "#/components/schemas/GenericError" + description: Request is invalid. + content: + application/json: + schema: + $ref: "#/components/schemas/GenericError" 500: - description: Extension download request failed. - content: - application/json: - schema: - $ref: "#/components/schemas/GenericError" + description: Extension download request failed. + content: + application/json: + schema: + $ref: "#/components/schemas/GenericError" components: securitySchemes: