package edu.tamu.weaver.auth.controller.handler;

import static edu.tamu.weaver.auth.AuthConstants.UNAUTHORIZED_API_RESPONSE;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.weaver.response.ApiResponse;

@RestController
@ControllerAdvice
public class AuthRestExceptionHandler {

    @ExceptionHandler(AccessDeniedException.class)
    public ApiResponse handleAccessDeniedExceptionRest(AccessDeniedException exception) {
        return UNAUTHORIZED_API_RESPONSE;
    }

}
@@ -120,16 +120,60 @@
 PONSE;%0A%0A
+import org.springframework.http.HttpStatus;%0A
 import o
@@ -230,16 +230,16 @@
 eption;%0A
-
 import o
@@ -360,16 +360,140 @@
 andler;%0A
+import org.springframework.web.bind.annotation.ResponseBody;%0Aimport org.springframework.web.bind.annotation.ResponseStatus;%0A
 import o
@@ -669,16 +669,16 @@
 dler %7B%0A%0A
-
     @Exc
@@ -720,16 +720,87 @@
 .class)%0A
+    @ResponseStatus(value = HttpStatus.UNAUTHORIZED)%0A    @ResponseBody%0A
     publ

return 401 for unauthorized