From 1a605a60c91e81b9301b3100082df330571d5624 Mon Sep 17 00:00:00 2001 From: Matthew Nichols Date: Mon, 3 Jun 2024 11:51:37 -0600 Subject: [PATCH] fix: respond with status 400 if the input payload is unparsable Current behavior is to respond with 500 if we are unable to deserialize the input. This changes to use a custom exception that will set the status to 400. --- .../path/model/mdx/web/DateVersionedResponse.java | 2 +- .../web/WebPathRequestSerializationException.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 mdx-web/src/main/java/com/mx/path/model/mdx/web/WebPathRequestSerializationException.java diff --git a/mdx-web/src/main/java/com/mx/path/model/mdx/web/DateVersionedResponse.java b/mdx-web/src/main/java/com/mx/path/model/mdx/web/DateVersionedResponse.java index 4ca388b5..004685dc 100644 --- a/mdx-web/src/main/java/com/mx/path/model/mdx/web/DateVersionedResponse.java +++ b/mdx-web/src/main/java/com/mx/path/model/mdx/web/DateVersionedResponse.java @@ -92,7 +92,7 @@ public final ResponseEntity call(HttpServletRequest request) { try { requestObject = gson.fromJson(requestBody, requestType); } catch (Exception e) { - throw new PathRequestSerializableException(); + throw new WebPathRequestSerializationException(requestType.getTypeName(), e); } } diff --git a/mdx-web/src/main/java/com/mx/path/model/mdx/web/WebPathRequestSerializationException.java b/mdx-web/src/main/java/com/mx/path/model/mdx/web/WebPathRequestSerializationException.java new file mode 100644 index 00000000..291ac29c --- /dev/null +++ b/mdx-web/src/main/java/com/mx/path/model/mdx/web/WebPathRequestSerializationException.java @@ -0,0 +1,13 @@ +package com.mx.path.model.mdx.web; + +import com.mx.path.core.common.accessor.PathResponseStatus; +import com.mx.path.core.common.serialization.PathRequestSerializableException; + +public class WebPathRequestSerializationException extends PathRequestSerializableException { + public WebPathRequestSerializationException(String originalType, Throwable cause) { + super(); + super.initCause(cause); + this.setOriginalType(originalType); + this.setStatus(PathResponseStatus.BAD_REQUEST); + } +}