use of io.micronaut.http.annotation.Error in project kestra by kestra-io.
the class ErrorController method error.
@Error(global = true)
public HttpResponse<JsonError> error(HttpRequest<?> request, ConversionErrorException e) {
if (e.getConversionError().getCause() instanceof InvalidTypeIdException) {
try {
InvalidTypeIdException invalidTypeIdException = ((InvalidTypeIdException) e.getConversionError().getCause());
String path = path(invalidTypeIdException);
Field typeField = InvalidTypeIdException.class.getDeclaredField("_typeId");
typeField.setAccessible(true);
Object typeClass = typeField.get(invalidTypeIdException);
JsonError error = new JsonError("Invalid type: " + typeClass).link(Link.SELF, Link.of(request.getUri())).embedded("errors", Arrays.asList(new JsonError("Invalid type: " + typeClass).path(path), new JsonError(e.getMessage()).path(path)));
return jsonError(error, HttpStatus.UNPROCESSABLE_ENTITY, "Invalid entity");
} catch (Exception ignored) {
}
} else if (e.getConversionError().getCause() instanceof JsonMappingException) {
try {
JsonMappingException jsonMappingException = ((JsonMappingException) e.getConversionError().getCause());
String path = path(jsonMappingException);
JsonError error = new JsonError("Invalid json mapping").link(Link.SELF, Link.of(request.getUri())).embedded("errors", Collections.singletonList(new JsonError(e.getMessage()).path(path)));
return jsonError(error, HttpStatus.UNPROCESSABLE_ENTITY, "Invalid json mapping");
} catch (Exception ignored) {
}
}
return jsonError(request, e, HttpStatus.UNPROCESSABLE_ENTITY, "Internal server error");
}
use of io.micronaut.http.annotation.Error in project akhq by tchiotludo.
the class ErrorController method error.
@Error(global = true)
public HttpResponse<?> error(HttpRequest<?> request, Throwable e) {
log.error(e.getMessage(), e);
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
JsonError error = new JsonError("Internal Server Error: " + e.getMessage()).link(Link.SELF, Link.of(request.getUri())).embedded("stacktrace", new JsonError(stringWriter.toString()));
return HttpResponse.<JsonError>serverError().body(error);
}
Aggregations