mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 23:47:29 +00:00
修复RouterHandlerFactory异常信息泄露:Future失败和异常捕获时返回通用错误消息,详细异常仅记日志
This commit is contained in:
@@ -127,8 +127,9 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
// 错误请求处理
|
||||
mainRouter.errorHandler(405, ctx -> doFireJsonResultResponse(ctx, JsonResult
|
||||
.error("Method Not Allowed", 405)));
|
||||
mainRouter.errorHandler(404, ctx -> ctx.response().setStatusCode(404).setChunked(true)
|
||||
.end("Internal server error: 404 not found"));
|
||||
mainRouter.errorHandler(404, ctx -> {
|
||||
ctx.response().setStatusCode(404).end("404 not found");
|
||||
});
|
||||
|
||||
return mainRouter;
|
||||
}
|
||||
@@ -408,22 +409,18 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
doFireJsonResultResponse(ctx, JsonResult.data(null));
|
||||
}
|
||||
|
||||
}).onFailure(e -> doFireJsonResultResponse(ctx, JsonResult.error(e.getMessage()), 500));
|
||||
}).onFailure(e -> {
|
||||
LOGGER.error("请求处理失败", e);
|
||||
doFireJsonResultResponse(ctx, JsonResult.error("服务器内部错误"), 500);
|
||||
});
|
||||
} else {
|
||||
doFireJsonResultResponse(ctx, JsonResult.data(data));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
String err = e.getMessage();
|
||||
if (e.getCause() != null) {
|
||||
if (e.getCause() instanceof InvocationTargetException) {
|
||||
err = ((InvocationTargetException) e.getCause()).getTargetException().getMessage();
|
||||
} else {
|
||||
err = e.getCause().getMessage();
|
||||
}
|
||||
}
|
||||
doFireJsonResultResponse(ctx, JsonResult.error(err), 500);
|
||||
LOGGER.error("请求处理异常", e);
|
||||
doFireJsonResultResponse(ctx, JsonResult.error("服务器内部错误"), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user