0
我試圖爲CompletionException編寫自定義異常映射器,並在這種情況下顯示圖像。這是我的映射:當我的代碼拋出CompletionException
在澤西島中顯示圖像ExceptionMapper
@Provider
public class CustomCompleteExceptionManager implements ExceptionMapper<CompletionException> {
@Override
public Response toResponse(CompletionException e) {
return Response
.status(Response.Status.BAD_REQUEST)
.entity(Paths.get("error.png").toFile())
.type("image/img")
.build();
}
方法toResponse被調用,但瀏覽器不顯示error.png
。我得到一個錯誤:
This site can’t be reached
The webpage at http://localhost:8080/cf/point might be temporarily down or it may have moved permanently to a new web address.
當我寫的只是字符串消息Response
它工作正常:
@Provider
public class CustomCompleteExceptionManager implements ExceptionMapper<CompletionException> {
@Override
public Response toResponse(CompletionException e) {
return Response
.status(Response.Status.BAD_REQUEST)
.entity(e.getMessage())
.build();
}
可能是什麼問題呢?