mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Give better responses on errors.
This commit is contained in:
parent
2eb424dcae
commit
d53459171f
2 changed files with 13 additions and 5 deletions
|
@ -7,11 +7,14 @@ import static io.activej.http.HttpHeaders.CONTENT_TYPE;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
@ -191,11 +194,15 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||
|
||||
private @NotNull HttpResponse getErrorResponse(Exception e) {
|
||||
|
||||
if (e instanceof ExecutionException)
|
||||
e = (Exception) e.getCause();
|
||||
|
||||
if (!(e instanceof AgeRestrictedContentException || e instanceof ContentNotAvailableException))
|
||||
e.printStackTrace();
|
||||
|
||||
try {
|
||||
return getJsonResponse(500,
|
||||
Constants.mapper.writeValueAsBytes(new ErrorResponse(ExceptionUtils.getStackTrace(e))), "private");
|
||||
return getJsonResponse(500, Constants.mapper
|
||||
.writeValueAsBytes(new ErrorResponse(ExceptionUtils.getStackTrace(e), e.getMessage())), "private");
|
||||
} catch (JsonProcessingException ex) {
|
||||
return HttpResponse.ofCode(500);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@ package me.kavin.piped.utils.resp;
|
|||
|
||||
public class ErrorResponse {
|
||||
|
||||
public final String error;
|
||||
public final String error, message;
|
||||
|
||||
public ErrorResponse(String error) {
|
||||
public ErrorResponse(String error, String message) {
|
||||
this.error = error;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue