All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.infusers.core.exception.GlobalExceptionHandler Maven / Gradle / Ivy

package com.infusers.core.exception;

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 org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.context.request.async.AsyncRequestTimeoutException;

import com.infusers.core.exception.api.FileNotFoundException;
import com.infusers.core.exception.sim.OrderNotFoundException;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(OrderNotFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public ResponseEntity handleOrderNotFoundException(OrderNotFoundException ex) {
        return new ResponseEntity<>(ex.getMessage(), HttpStatus.NOT_FOUND);
    }
    
    @ExceptionHandler(FileNotFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public ResponseEntity handleFileNotFoundException(FileNotFoundException ex) {
        return new ResponseEntity<>(ex.getMessage(), HttpStatus.NOT_FOUND);
    }
    
    @ExceptionHandler(AsyncRequestTimeoutException.class)
    public ResponseEntity handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex) {
        // Handle timeout exception
        return ResponseEntity.status(HttpStatus.REQUEST_TIMEOUT).body("Request timed out");
    }    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy