Move storage exception handling to common module
parent
f170b57ea5
commit
119e49338a
|
@ -1,5 +1,7 @@
|
|||
package ba.steleks.storage;
|
||||
|
||||
import ba.steleks.storage.error.exception.StorageException;
|
||||
import ba.steleks.storage.error.exception.StorageFileNotFoundException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
|
@ -12,7 +14,6 @@ import java.net.MalformedURLException;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.FileOwnerAttributeView;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package ba.steleks.storage.error;/**
|
||||
* Created by ensar on 16/04/17.
|
||||
*/
|
||||
|
||||
import ba.steleks.storage.error.exception.StorageFileNotFoundException;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ControllerAdvice
|
||||
public class StorageErrorHandler {
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(StorageErrorHandler.class.getName());
|
||||
|
||||
@ExceptionHandler(StorageFileNotFoundException.class)
|
||||
public ResponseEntity handleStorageFileNotFound(StorageFileNotFoundException exc) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package ba.steleks.storage;
|
||||
package ba.steleks.storage.error.exception;
|
||||
|
||||
public class StorageException extends RuntimeException {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package ba.steleks.storage;
|
||||
package ba.steleks.storage.error.exception;
|
||||
|
||||
|
||||
public class StorageFileNotFoundException extends StorageException {
|
|
@ -2,9 +2,8 @@ package ba.steleks.controller;
|
|||
|
||||
import ba.steleks.error.exception.ExternalServiceException;
|
||||
import ba.steleks.model.Media;
|
||||
import ba.steleks.repository.EventsJpaRepository;
|
||||
import ba.steleks.repository.MediaJpaRepository;
|
||||
import ba.steleks.storage.StorageFileNotFoundException;
|
||||
import ba.steleks.storage.error.exception.StorageFileNotFoundException;
|
||||
import ba.steleks.storage.StorageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
|
|
|
@ -2,10 +2,8 @@ package ba.steleks.controller;
|
|||
|
||||
import ba.steleks.model.User;
|
||||
import ba.steleks.repository.UsersJpaRepository;
|
||||
import ba.steleks.storage.StorageFileNotFoundException;
|
||||
import ba.steleks.storage.StorageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.RepositoryRestController;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -56,9 +54,4 @@ public class ProfilePictureController {
|
|||
|
||||
return "redirect:/";
|
||||
}
|
||||
|
||||
@ExceptionHandler(StorageFileNotFoundException.class)
|
||||
public ResponseEntity handleStorageFileNotFound(StorageFileNotFoundException exc) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue