chore(release): v1.1 #2
@ -2,13 +2,16 @@ package com.techivw.webprice.infrastructure.in.controllers.handlers;
|
|||||||
|
|
||||||
import com.techivw.webprice.application.exceptions.NotFoundException;
|
import com.techivw.webprice.application.exceptions.NotFoundException;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||||
|
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
@ -24,4 +27,27 @@ public class AdapterExceptionHandler {
|
|||||||
|
|
||||||
return new ResponseEntity<>(body, NOT_FOUND);
|
return new ResponseEntity<>(body, NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MissingServletRequestParameterException.class)
|
||||||
|
public ResponseEntity<Map<String, Object>> handleMissingParamException(MissingServletRequestParameterException ex) {
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("timestamp", new Date());
|
||||||
|
body.put("status", BAD_REQUEST.value());
|
||||||
|
body.put("error", "Bad Request");
|
||||||
|
body.put("message", "Required parameter '" + ex.getParameterName() + "' is missing");
|
||||||
|
|
||||||
|
return new ResponseEntity<>(body, BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
||||||
|
public ResponseEntity<Map<String, Object>> handleTypeMismatchException(MethodArgumentTypeMismatchException ex) {
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("timestamp", new Date());
|
||||||
|
body.put("status", BAD_REQUEST.value());
|
||||||
|
body.put("error", "Bad Request");
|
||||||
|
body.put("message", "Parameter '" + ex.getName() + "' has invalid format.");
|
||||||
|
|
||||||
|
return new ResponseEntity<>(body, BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user