Move storage exception handling to common module

master
esensar 2017-04-16 18:05:22 +02:00
parent f170b57ea5
commit 119e49338a
6 changed files with 26 additions and 12 deletions

View File

@ -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

View File

@ -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();
}
}

View File

@ -1,4 +1,4 @@
package ba.steleks.storage;
package ba.steleks.storage.error.exception;
public class StorageException extends RuntimeException {

View File

@ -1,4 +1,4 @@
package ba.steleks.storage;
package ba.steleks.storage.error.exception;
public class StorageFileNotFoundException extends StorageException {

View File

@ -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;

View File

@ -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();
}
}