add json content-type for exception response

This commit is contained in:
Francis Dong
2021-03-19 17:47:48 +08:00
committed by dxfeng10
parent 4f5864002b
commit 3cfd9096bb

View File

@@ -88,6 +88,7 @@ public class FilterExceptionHandlerConfig {
WebUtils.request2stringBuilder(exchange, b); WebUtils.request2stringBuilder(exchange, b);
log.error(b.toString(), LogService.BIZ_ID, exchange.getRequest().getId(), t); log.error(b.toString(), LogService.BIZ_ID, exchange.getRequest().getId(), t);
String s = RespEntity.toJson(HttpStatus.INTERNAL_SERVER_ERROR.value(), t.getMessage(), exchange.getRequest().getId()); String s = RespEntity.toJson(HttpStatus.INTERNAL_SERVER_ERROR.value(), t.getMessage(), exchange.getRequest().getId());
resp.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
vm = resp.writeWith(Mono.just(resp.bufferFactory().wrap(s.getBytes()))); vm = resp.writeWith(Mono.just(resp.bufferFactory().wrap(s.getBytes())));
} else { } else {
vm = WebUtils.responseError(exchange, filterExceptionHandler, HttpStatus.INTERNAL_SERVER_ERROR.value(), t.getMessage(), t); vm = WebUtils.responseError(exchange, filterExceptionHandler, HttpStatus.INTERNAL_SERVER_ERROR.value(), t.getMessage(), t);