You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.0 KiB

  1. package com.dreamworks.boditech.utils;
  2. import com.dreamworks.boditech.controller.entity.ApiResponse;
  3. import org.springframework.web.bind.annotation.ControllerAdvice;
  4. import org.springframework.web.bind.annotation.ExceptionHandler;
  5. import org.springframework.web.bind.annotation.ResponseBody;
  6. @ControllerAdvice
  7. public class AppExceptionHandler {
  8. @ExceptionHandler(value = AppRuntimeException.class)
  9. @ResponseBody
  10. public ApiResponse handleAppRuntimeException(AppRuntimeException e) {
  11. ApiResponse response = new ApiResponse();
  12. response.success = false;
  13. response.message = e.getMessage();
  14. response.data = null;
  15. response.code = e.getCode();
  16. return response;
  17. }
  18. @ExceptionHandler(value = RuntimeException.class)
  19. @ResponseBody
  20. public ApiResponse handleRuntimeException(RuntimeException e ) {
  21. ApiResponse response = new ApiResponse();
  22. response.success = false;
  23. response.message = e.getMessage();
  24. response.data = null;
  25. return response;
  26. }
  27. }