Don't log errors on NotFoundExceptions in Jetty (#3931)

This commit is contained in:
Kai Kreuzer 2023-12-19 21:16:05 +01:00 committed by GitHub
parent cb1b355869
commit 04cd8408de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,7 @@ package org.openhab.core.io.rest.core.internal;
import java.io.IOException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
@ -50,6 +51,12 @@ public class JSONResponseExceptionMapper implements ExceptionMapper<Exception> {
logger.debug("Failed writing HTTP response, since other side closed the connection", e);
// Returning null results in a Response.Status.NO_CONTENT response.
return null;
} else if (e instanceof NotFoundException) {
// we catch this exception to avoid confusion errors in the log file, since this is not any error situation
// see https://github.com/openhab/openhab-distro/issues/1616
logger.debug("Requested resource not (yet) found", e);
// Returning null results in a Response.Status.NO_CONTENT response.
return Response.status(Response.Status.NOT_FOUND).build();
} else {
logger.error("Unexpected exception occurred while processing REST request.", e);
return delegate.toResponse(e);