-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show actionable error for large builder responses (#11328)
- Loading branch information
Showing
6 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...commons-server/src/main/java/io/airbyte/commons/server/errors/ClientExceptionHandler.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,37 @@ | ||
/* | ||
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.commons.server.errors; | ||
|
||
import io.airbyte.commons.json.Jsons; | ||
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 org.openapitools.client.infrastructure.ClientException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Handles unprocessable content exceptions. | ||
*/ | ||
@Produces | ||
@Singleton | ||
public class ClientExceptionHandler implements ExceptionHandler<ClientException, HttpResponse> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ClientExceptionHandler.class); | ||
|
||
@Override | ||
public HttpResponse handle(final HttpRequest request, final ClientException exception) { | ||
return HttpResponse.status(HttpStatus.valueOf(exception.getStatusCode())) | ||
.body(Jsons.serialize(new MessageObject(exception.getMessage()))) | ||
.contentType(MediaType.APPLICATION_JSON); | ||
} | ||
|
||
private record MessageObject(String message) {} | ||
|
||
} |
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
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
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
...r/src/main/java/io/airbyte/connector_builder/exceptions/UnprocessableEntityException.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) 2020-2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.connector_builder.exceptions; | ||
|
||
import io.airbyte.commons.server.errors.KnownException; | ||
import io.micronaut.http.HttpStatus; | ||
|
||
/** | ||
* Thrown when the server understands the content type of the request entity, and the syntax of the | ||
* request entity is correct, but it was unable to process the contained instructions. | ||
*/ | ||
public class UnprocessableEntityException extends KnownException { | ||
|
||
public UnprocessableEntityException(final String msg) { | ||
super(msg); | ||
} | ||
|
||
public UnprocessableEntityException(final String msg, final Throwable t) { | ||
super(msg, t); | ||
} | ||
|
||
@Override | ||
public int getHttpCode() { | ||
return HttpStatus.UNPROCESSABLE_ENTITY.getCode(); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...ain/java/io/airbyte/connector_builder/exceptions/UnprocessableEntityExceptionHandler.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) 2020-2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.connector_builder.exceptions; | ||
|
||
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; | ||
|
||
/** | ||
* Handles unprocessable content exceptions. | ||
*/ | ||
@Produces | ||
@Singleton | ||
public class UnprocessableEntityExceptionHandler implements ExceptionHandler<UnprocessableEntityException, HttpResponse> { | ||
|
||
@Override | ||
public HttpResponse handle(final HttpRequest request, final UnprocessableEntityException exception) { | ||
return HttpResponse.status(HttpStatus.valueOf(exception.getHttpCode())) | ||
.body(exception.getMessage()) | ||
.contentType(MediaType.TEXT_PLAIN); | ||
} | ||
|
||
} |