Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save MafaldaLandeiro/0a72da52ecb4deffeeb35f29e197c9d8 to your computer and use it in GitHub Desktop.

Select an option

Save MafaldaLandeiro/0a72da52ecb4deffeeb35f29e197c9d8 to your computer and use it in GitHub Desktop.
Controller Advice
package org.SpringRestfulServiceExceptionHandler.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice(basePackages = { "org.SpringRestfulServiceExceptionHandler.controller" })
public class RestfulResponseExceptionHandler {
@ExceptionHandler(value = NumberFormatException.class)
public ResponseEntity<Object> numberFormatExceptionExceptionHandler(Exception ex) {
String response = "ERROR MESSAGE";
return new ResponseEntity<Object>(response, HttpStatus.BAD_REQUEST);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment