package com.github.dhavalmehta1997.savetogoogledrive.advice;

import com.github.dhavalmehta1997.savetogoogledrive.exception.ApiException;
import com.github.dhavalmehta1997.savetogoogledrive.model.ApiError;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.logging.Level;
import java.util.logging.Logger;

@ControllerAdvice
public class WebRestControllerAdvice {

    @ExceptionHandler(ApiException.class)
    public ResponseEntity<ApiError> handleApiException(ApiException ex) {
        ApiError apiError = new ApiError(ex.getStatus(), ex.getMessage(), null);
        return new ResponseEntity<>(apiError, apiError.getStatus());
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity<ApiError> handleGenericException(Exception ex) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
        ApiError apiError = new ApiError(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), null);
        return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

@@ -66,145 +66,67 @@
 ort 
-com.github.dhavalmehta1997.savetogoogledrive.exception.ApiException;%0Aimport com.github.dhavalmehta1997.savetogoogledrive.model.ApiErro
+java.util.logging.Level;%0Aimport java.util.logging.Logge
 r;%0A
+%0A
 impo
@@ -213,16 +213,87 @@
 Entity;%0A
+import org.springframework.web.HttpRequestMethodNotSupportedException;%0A
 import o
@@ -426,63 +426,142 @@
 ort 
-java.util.logging.Level;%0Aimport java.util.logging.Logge
+com.github.dhavalmehta1997.savetogoogledrive.exception.ApiException;%0Aimport com.github.dhavalmehta1997.savetogoogledrive.model.ApiErro
 r;%0A%0A
@@ -618,20 +618,17 @@
 vice %7B%0A%0A
-    
+%09
 @Excepti
@@ -649,36 +649,33 @@
 xception.class)%0A
-    
+%09
 public ResponseE
@@ -728,24 +728,18 @@
 n ex) %7B%0A
-        
+%09%09
 ApiError
@@ -799,32 +799,360 @@
 e(), null);%0A
-        
+%09%09return new ResponseEntity%3C%3E(apiError, apiError.getStatus());%0A%09%7D%0A%0A%09@ExceptionHandler(HttpRequestMethodNotSupportedException.class)%0A%09public ResponseEntity%3CApiError%3E handleMethodNotSupportedException(HttpRequestMethodNotSupportedException ex) %7B%0A%09%09ApiError apiError = new ApiError(HttpStatus.METHOD_NOT_ALLOWED, ex.getMessage(), null);%0A%09%09
 return new R
@@ -1204,19 +1204,13 @@
 ));%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Exc
@@ -1240,20 +1240,17 @@
 .class)%0A
-    
+%09
 public R
@@ -1312,24 +1312,18 @@
 n ex) %7B%0A
-        
+%09%09
 Logger.g
@@ -1382,24 +1382,18 @@
 l, ex);%0A
-        
+%09%09
 ApiError
@@ -1479,16 +1479,10 @@
 l);%0A
-        
+%09%09
 retu
@@ -1554,12 +1554,9 @@
 R);%0A
-    
+%09
 %7D%0A%7D%0A

handle HttpRequestMethodNotSupportedException