From 29c7a0b93ba3514e772d1b9fc1029dce6a75fc2d Mon Sep 17 00:00:00 2001 From: dylan Date: Thu, 30 Jan 2025 18:40:58 +0100 Subject: [PATCH] Return bad request instead of unauthorized --- openapi.yml | 10 ++++++++++ .../swisssignchallenge/filters/JwtRequestFilter.java | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/openapi.yml b/openapi.yml index 090c0ee..5933bfa 100644 --- a/openapi.yml +++ b/openapi.yml @@ -18,6 +18,10 @@ servers: tags: - name: hello description: "" + - name: token + description: "" + - name: signing-request + description: "" paths: /hello: @@ -51,6 +55,12 @@ paths: application/json: schema: $ref: "#/components/schemas/CreateSessionResponse" + 400: + description: "Couldn't process request" + content: + application/json: + schema: + $ref: "#/components/schemas/ErrorResponse" components: schemas: diff --git a/src/main/java/ch/dlmw/swisssignchallenge/filters/JwtRequestFilter.java b/src/main/java/ch/dlmw/swisssignchallenge/filters/JwtRequestFilter.java index 3f326ef..b52edac 100644 --- a/src/main/java/ch/dlmw/swisssignchallenge/filters/JwtRequestFilter.java +++ b/src/main/java/ch/dlmw/swisssignchallenge/filters/JwtRequestFilter.java @@ -63,8 +63,8 @@ public class JwtRequestFilter extends OncePerRequestFilter { filterChain.doFilter(request, response); } catch (Exception e) { response.setContentType("application/json"); - response.setStatus(HttpStatus.UNAUTHORIZED.value()); - response.getWriter().write(objectMapper.writeValueAsString(new ErrorResponse("Couldn't authenticate", HttpStatus.UNAUTHORIZED.value()))); + response.setStatus(HttpStatus.BAD_REQUEST.value()); + response.getWriter().write(objectMapper.writeValueAsString(new ErrorResponse("Couldn't authenticate", HttpStatus.BAD_REQUEST.value()))); } }