-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bmoric/restore old interface (#21235)
* Re introduce old exception mapper * Use mapper
- Loading branch information
1 parent
59ff2a2
commit 449b252
Showing
12 changed files
with
274 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
airbyte-server/src/main/java/io/airbyte/server/errors/InvalidInputExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
import io.airbyte.api.model.generated.InvalidInputExceptionInfo; | ||
import io.airbyte.api.model.generated.InvalidInputProperty; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpResponse; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Produces; | ||
import io.micronaut.http.server.exceptions.ExceptionHandler; | ||
import jakarta.inject.Singleton; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.validation.ConstraintViolation; | ||
import javax.validation.ConstraintViolationException; | ||
import org.apache.logging.log4j.core.util.Throwables; | ||
|
||
// https://www.baeldung.com/jersey-bean-validation#custom-exception-handler | ||
// handles exceptions related to the request body not matching the openapi config. | ||
@Produces | ||
@Singleton | ||
@Requires(classes = ConstraintViolationException.class) | ||
public class InvalidInputExceptionHandler implements ExceptionHandler<ConstraintViolationException, HttpResponse> { | ||
|
||
public static InvalidInputExceptionInfo infoFromConstraints(final ConstraintViolationException cve) { | ||
final InvalidInputExceptionInfo exceptionInfo = new InvalidInputExceptionInfo() | ||
.exceptionClassName(cve.getClass().getName()) | ||
.message("Some properties contained invalid input.") | ||
.exceptionStack(Throwables.toStringList(cve)); | ||
|
||
final List<InvalidInputProperty> props = new ArrayList<InvalidInputProperty>(); | ||
for (final ConstraintViolation<?> cv : cve.getConstraintViolations()) { | ||
props.add(new InvalidInputProperty() | ||
.propertyPath(cv.getPropertyPath().toString()) | ||
.message(cv.getMessage()) | ||
.invalidValue(cv.getInvalidValue() != null ? cv.getInvalidValue().toString() : "null")); | ||
} | ||
exceptionInfo.validationErrors(props); | ||
return exceptionInfo; | ||
} | ||
|
||
@Override | ||
public HttpResponse handle(final HttpRequest request, final ConstraintViolationException exception) { | ||
return HttpResponse.status(HttpStatus.BAD_REQUEST) | ||
.body(Jsons.serialize(InvalidInputExceptionHandler.infoFromConstraints(exception))) | ||
.contentType(MediaType.APPLICATION_JSON_TYPE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
airbyte-server/src/main/java/io/airbyte/server/errors/InvalidJsonExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
import com.fasterxml.jackson.core.JsonParseException; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpResponse; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Produces; | ||
import io.micronaut.http.server.exceptions.ExceptionHandler; | ||
import jakarta.inject.Singleton; | ||
|
||
@Produces | ||
@Singleton | ||
@Requires(classes = JsonParseException.class) | ||
public class InvalidJsonExceptionHandler implements ExceptionHandler<JsonParseException, HttpResponse> { | ||
|
||
@Override | ||
public HttpResponse handle(final HttpRequest request, final JsonParseException exception) { | ||
return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY) | ||
.body( | ||
KnownException.infoFromThrowableWithMessage(exception, "Invalid json. " + exception.getMessage() + " " + exception.getOriginalMessage())) | ||
.contentType(MediaType.APPLICATION_JSON_TYPE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
airbyte-server/src/main/java/io/airbyte/server/errors/InvalidJsonInputExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpResponse; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Produces; | ||
import io.micronaut.http.server.exceptions.ExceptionHandler; | ||
import jakarta.inject.Singleton; | ||
|
||
@Produces | ||
@Singleton | ||
@Requires(classes = JsonMappingException.class) | ||
public class InvalidJsonInputExceptionHandler implements ExceptionHandler<JsonMappingException, HttpResponse> { | ||
|
||
@Override | ||
public HttpResponse handle(final HttpRequest request, final JsonMappingException exception) { | ||
return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY) | ||
.body(KnownException.infoFromThrowableWithMessage(exception, | ||
"Invalid json input. " + exception.getMessage() + " " + exception.getOriginalMessage())) | ||
.contentType(MediaType.APPLICATION_JSON_TYPE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
airbyte-server/src/main/java/io/airbyte/server/errors/KnownExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
import io.airbyte.commons.json.Jsons; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpResponse; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Produces; | ||
import io.micronaut.http.server.exceptions.ExceptionHandler; | ||
import jakarta.inject.Singleton; | ||
|
||
@Produces | ||
@Singleton | ||
@Requires(classes = KnownException.class) | ||
public class KnownExceptionHandler implements ExceptionHandler<KnownException, HttpResponse> { | ||
|
||
@Override | ||
public HttpResponse handle(HttpRequest request, KnownException exception) { | ||
return HttpResponse.status(HttpStatus.valueOf(exception.getHttpCode())) | ||
.body(Jsons.serialize(exception.getKnownExceptionInfo())) | ||
.contentType(MediaType.APPLICATION_JSON_TYPE); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
airbyte-server/src/main/java/io/airbyte/server/errors/NotFoundExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpResponse; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Produces; | ||
import io.micronaut.http.server.exceptions.ExceptionHandler; | ||
import jakarta.inject.Singleton; | ||
import javax.ws.rs.NotFoundException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Produces | ||
@Singleton | ||
@Requires(classes = NotFoundException.class) | ||
public class NotFoundExceptionHandler implements ExceptionHandler<NotFoundException, HttpResponse> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(NotFoundExceptionHandler.class); | ||
|
||
@Override | ||
public HttpResponse handle(final HttpRequest request, final NotFoundException exception) { | ||
final IdNotFoundKnownException idnf = new IdNotFoundKnownException("Object not found. " + exception.getMessage(), exception); | ||
LOGGER.error("Not found exception", idnf.getNotFoundKnownExceptionInfo()); | ||
|
||
return HttpResponse.status(HttpStatus.NOT_FOUND) | ||
.body(KnownException.infoFromThrowableWithMessage(exception, "Internal Server Error: " + exception.getMessage())) | ||
.contentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.