ADD improved error handling
This commit is contained in:
@@ -35,14 +35,4 @@ public class DownloadController {
|
|||||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
.body(resource);
|
.body(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(JobNotFound.class)
|
|
||||||
public ResponseEntity<String> handleFileNotFound(JobNotFound ex) {
|
|
||||||
return ResponseEntity.status(404).body(ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(JobNotFinished.class)
|
|
||||||
public ResponseEntity<String> handleJobNotFinished(JobNotFinished ex) {
|
|
||||||
return ResponseEntity.status(404).body(ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,4 @@ public class EditController {
|
|||||||
return new ResponseEntity<>(editService.getProgress(uuid), HttpStatus.OK);
|
return new ResponseEntity<>(editService.getProgress(uuid), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(IllegalArgumentException.class)
|
|
||||||
public ResponseEntity<String> handleIllegalArgument(IllegalArgumentException ex) {
|
|
||||||
return ResponseEntity.status(404).body(ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.ddf.vodsystem.controllers;
|
||||||
|
|
||||||
|
import com.ddf.vodsystem.exceptions.JobNotFinished;
|
||||||
|
import com.ddf.vodsystem.exceptions.JobNotFound;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
@ExceptionHandler(IllegalArgumentException.class)
|
||||||
|
public ResponseEntity<String> handleIllegalArgument(IllegalArgumentException ex) {
|
||||||
|
return ResponseEntity.status(400).body(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(JobNotFound.class)
|
||||||
|
public ResponseEntity<String> handleFileNotFound(JobNotFound ex) {
|
||||||
|
return ResponseEntity.status(404).body(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(JobNotFinished.class)
|
||||||
|
public ResponseEntity<String> handleJobNotFinished(JobNotFinished ex) {
|
||||||
|
return ResponseEntity.status(202).body(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,5 +4,6 @@ public enum JobStatus {
|
|||||||
NOT_READY,
|
NOT_READY,
|
||||||
PENDING,
|
PENDING,
|
||||||
RUNNING,
|
RUNNING,
|
||||||
FINISHED
|
FINISHED,
|
||||||
|
FAILED
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ddf.vodsystem.exceptions;
|
||||||
|
|
||||||
|
public class FFMPEGException extends RuntimeException {
|
||||||
|
public FFMPEGException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import java.util.List;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.ddf.vodsystem.exceptions.FFMPEGException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -109,7 +110,6 @@ public class CompressionService {
|
|||||||
logger.info("FFMPEG starting...");
|
logger.info("FFMPEG starting...");
|
||||||
|
|
||||||
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getClipConfig());
|
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getClipConfig());
|
||||||
//pb.redirectErrorStream(true);
|
|
||||||
Process process = pb.start();
|
Process process = pb.start();
|
||||||
job.setStatus(JobStatus.RUNNING);
|
job.setStatus(JobStatus.RUNNING);
|
||||||
|
|
||||||
@@ -127,6 +127,11 @@ public class CompressionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.waitFor() != 0) {
|
||||||
|
job.setStatus(JobStatus.FAILED);
|
||||||
|
throw new FFMPEGException("FFMPEG process failed");
|
||||||
|
}
|
||||||
|
|
||||||
job.setStatus(JobStatus.FINISHED);
|
job.setStatus(JobStatus.FINISHED);
|
||||||
logger.info("FFMPEG finished");
|
logger.info("FFMPEG finished");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ public class EditService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (clipConfig.getFileSize() != null) {
|
||||||
|
if (clipConfig.getFileSize() < 100) {
|
||||||
|
throw new IllegalArgumentException("File size cannot be less than 100kb");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
job.setClipConfig(clipConfig);
|
job.setClipConfig(clipConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user