From 4cc6667c1424e52e94622177d60c974ea9efeda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Mon, 19 Oct 2020 16:58:02 +0800 Subject: [PATCH] feat(Exception): add customized exception class --- .../BadResourceLocationException.java | 27 +++++++++++++++++++ .../exception/VideoNotFoundException.java | 20 ++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 media-streaming-spring-boot-autoconfigure/src/main/java/com/jmframework/boot/mediastreamingspringbootautoconfigure/exception/BadResourceLocationException.java create mode 100644 media-streaming-spring-boot-autoconfigure/src/main/java/com/jmframework/boot/mediastreamingspringbootautoconfigure/exception/VideoNotFoundException.java diff --git a/media-streaming-spring-boot-autoconfigure/src/main/java/com/jmframework/boot/mediastreamingspringbootautoconfigure/exception/BadResourceLocationException.java b/media-streaming-spring-boot-autoconfigure/src/main/java/com/jmframework/boot/mediastreamingspringbootautoconfigure/exception/BadResourceLocationException.java new file mode 100644 index 0000000..f3d5bc1 --- /dev/null +++ b/media-streaming-spring-boot-autoconfigure/src/main/java/com/jmframework/boot/mediastreamingspringbootautoconfigure/exception/BadResourceLocationException.java @@ -0,0 +1,27 @@ +package com.jmframework.boot.mediastreamingspringbootautoconfigure.exception; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +import java.io.IOException; + +/** + * Description: BadResourceLocationException, Exception thrown when the video location is inaccessible or does not + * exist. + * + * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com + * date 10/19/2020 4:55 PM + **/ +@Slf4j +@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) +public class BadResourceLocationException extends RuntimeException { + public BadResourceLocationException(String msg) { + super(msg); + log.error(msg); + } + + public BadResourceLocationException(String msg, IOException ex) { + super(msg, ex); + } +} diff --git a/media-streaming-spring-boot-autoconfigure/src/main/java/com/jmframework/boot/mediastreamingspringbootautoconfigure/exception/VideoNotFoundException.java b/media-streaming-spring-boot-autoconfigure/src/main/java/com/jmframework/boot/mediastreamingspringbootautoconfigure/exception/VideoNotFoundException.java new file mode 100644 index 0000000..3872ad8 --- /dev/null +++ b/media-streaming-spring-boot-autoconfigure/src/main/java/com/jmframework/boot/mediastreamingspringbootautoconfigure/exception/VideoNotFoundException.java @@ -0,0 +1,20 @@ +package com.jmframework.boot.mediastreamingspringbootautoconfigure.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +import java.io.FileNotFoundException; + +/** + * Description: BadResourceLocationException, Exception thrown when the video location is inaccessible or does not + * exist. + * + * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com + * date 10/19/2020 4:56 PM + **/ +@ResponseStatus(HttpStatus.NOT_FOUND) +public class VideoNotFoundException extends FileNotFoundException { + public VideoNotFoundException() { + super("video was not found"); + } +}