diff --git a/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt index e8b7173e..78c658f5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt @@ -19,6 +19,7 @@ package dev.usbharu.hideout.generate import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.core.MethodParameter +import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.support.WebDataBinderFactory import org.springframework.web.context.request.NativeWebRequest import org.springframework.web.method.annotation.ModelAttributeMethodProcessor @@ -56,12 +57,17 @@ class JsonOrFormModelMethodProcessor( return try { modelAttributeMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory) + } catch (e: MethodArgumentNotValidException) { + throw e } catch (exception: Exception) { try { requestResponseBodyMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory) + } catch (e: MethodArgumentNotValidException) { + throw e } catch (e: Exception) { logger.warn("Failed to bind request (1)", exception) logger.warn("Failed to bind request (2)", e) + throw IllegalArgumentException("Failed to bind request.") } } }