-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow to plug-in custom error handling for Connect server errors (
#8480) * ConnectExecutor has an immutable error handler as part of its state * ConnectExecutor#execute is an instance method now * CustomExecutors is a class now rather than an enum of static methods
- Loading branch information
Showing
32 changed files
with
1,094 additions
and
271 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
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
85 changes: 85 additions & 0 deletions
85
...b-rest-app/src/main/java/io/confluent/ksql/rest/server/execution/ConnectServerErrors.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,85 @@ | ||
/* | ||
* Copyright 2021 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.rest.server.execution; | ||
|
||
import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; | ||
import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED; | ||
|
||
import io.confluent.ksql.parser.tree.Statement; | ||
import io.confluent.ksql.rest.entity.KsqlEntity; | ||
import io.confluent.ksql.services.ConnectClient.ConnectResponse; | ||
import io.confluent.ksql.statement.ConfiguredStatement; | ||
import java.util.Optional; | ||
|
||
/** | ||
* An interface that allows to plug-in custom error handling for Connect server errors, such as 403 | ||
* Forbidden or 401 Unauthorized. | ||
*/ | ||
public interface ConnectServerErrors { | ||
|
||
/** | ||
* Handles error response for a create connector request. This method dispatches to specific | ||
* methods based on error codes. | ||
* | ||
* @param statement the executed statement | ||
* @param response the failed response | ||
* @return the optional {@link KsqlEntity} that represents server error | ||
*/ | ||
default Optional<KsqlEntity> handle( | ||
final ConfiguredStatement<? extends Statement> statement, | ||
final ConnectResponse<?> response) { | ||
if (response.httpCode() == FORBIDDEN.code()) { | ||
return handleForbidden(statement, response); | ||
} else if (response.httpCode() == UNAUTHORIZED.code()) { | ||
return handleUnauthorized(statement, response); | ||
} else { | ||
return handleDefault(statement, response); | ||
} | ||
} | ||
|
||
/** | ||
* This method allows altering error response on 403 Forbidden. | ||
* | ||
* @param statement the executed statement | ||
* @param response the failed response | ||
* @return the optional {@code KsqlEntity} that represents server error | ||
*/ | ||
Optional<KsqlEntity> handleForbidden( | ||
ConfiguredStatement<? extends Statement> statement, | ||
ConnectResponse<?> response); | ||
|
||
/** | ||
* This method allows altering error response on 401 Unauthorized. | ||
* | ||
* @param statement the executed statement | ||
* @param response the failed response | ||
* @return the optional {@code KsqlEntity} that represents server error | ||
*/ | ||
Optional<KsqlEntity> handleUnauthorized( | ||
ConfiguredStatement<? extends Statement> statement, | ||
ConnectResponse<?> response); | ||
|
||
/** | ||
* This method is a fall-back for errors that are not handled by the error-specific methods. | ||
* | ||
* @param statement the executed statement | ||
* @param response the failed response | ||
* @return the optional {@code KsqlEntity} that represents server error | ||
*/ | ||
Optional<KsqlEntity> handleDefault( | ||
ConfiguredStatement<? extends Statement> statement, | ||
ConnectResponse<?> response); | ||
} |
Oops, something went wrong.