0
私はこのページに例外をリダイレクトできるようにzuulサーバーの標準エラーページを作成しようとしていますか?zuulのスタンドエラーページを作成する[バージョン1.1.2]
現在、私は以下のようにzuul例外をキャッチするzuulフィルタを作成しました:
コードスニペット
@Override
public Object run() {
try {
RequestContext ctx = RequestContext.getCurrentContext();
Object e = ctx.get("error.exception");
if (e != null && e instanceof ZuulException) {
ZuulException zuulException = (ZuulException)e;
LOG.error("Zuul failure detected: " + zuulException.getMessage(), zuulException);
// Remove error code to prevent further error handling in follow up filters
ctx.remove("error.status_code");
// Populate context with new response values
ctx.setResponseBody("Internal Server Error : Please contact Phoenix Admin");
ctx.getResponse().setContentType("application/json");
ctx.setResponseStatusCode(500); //Can set any error code as excepted
}
}
catch (Exception ex) {
LOG.error("Exception filtering in custom error filter", ex);
ReflectionUtils.rethrowRuntimeException(ex);
}
return null;
}
はどんなアドバイスを感謝?
コンテンツタイプをtext/htmlに変更すると、jsonではなくページがスローされます。それはあなたが探しているものですか?または実際のページをスローしたい場合。 –
私は、レスポンスボディに直接ハードコードするのではなく、エラーページからコンテンツを読み込む必要があると考えています。私は、ファイルからコンテンツを読み込み、レスポンスボディに読み込むコードを書くことを考えています。 @GrinishNepalに点を付ける良い方法 – Joey