From 1c995c5de8ac098987d8feb80115426207e7ff62 Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Sat, 16 Sep 2017 09:49:19 -0600 Subject: [PATCH] Fix #569 Missing param exception Signed-off-by: Andrew DeMaria --- .../player/controller/SubsonicRESTController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java b/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java index 6a32f184..7b57dd21 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java @@ -41,11 +41,14 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.subsonic.restapi.*; +import org.subsonic.restapi.Error; import org.subsonic.restapi.PodcastStatus; import javax.servlet.http.HttpServletRequest; @@ -140,6 +143,13 @@ public class SubsonicRESTController { private static final String NOT_YET_IMPLEMENTED = "Not yet implemented"; private static final String NO_LONGER_SUPPORTED = "No longer supported"; + @ExceptionHandler(MissingServletRequestParameterException.class) + public void handleMissingRequestParam(HttpServletRequest request, + HttpServletResponse response, + MissingServletRequestParameterException exception) throws Exception { + error(request, response, ErrorCode.MISSING_PARAMETER, "Required param ("+exception.getParameterName()+") is missing"); + } + @RequestMapping(value = "/ping") public void ping(HttpServletRequest request, HttpServletResponse response) throws Exception { Response res = createResponse();