8000 MMSUP-745 add error codes to the connector Timeout errors by osolodovn-here · Pull Request #1561 · heremaps/xyz-hub · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MMSUP-745 add error codes to the connector Timeout errors #1561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.here.xyz.hub.connectors.models.Connector.RemoteFunctionConfig.Http;
import com.here.xyz.util.service.Core;
import com.here.xyz.util.service.HttpException;
import com.here.xyz.util.service.errors.DetailedHttpException;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
Expand Down Expand Up @@ -169,7 +170,7 @@ private void handleFailure(Marker marker, Handler<AsyncResult<byte[]>> callback,
t = new RuntimeException("Connection was already closed.", t);
logger.warn(marker, "Error while calling remote HTTP service", t);
if (t instanceof TimeoutException)
t = new HttpException(GATEWAY_TIMEOUT, "Connector timeout error.", t);
t = new DetailedHttpException("E318540", t);
if (!(t instanceof HttpException))
t = new HttpException(BAD_GATEWAY, "Connector error.", t);
callback.handle(Future.failedFuture(t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.here.xyz.responses.XyzResponse;
import com.here.xyz.util.service.Core;
import com.here.xyz.util.service.HttpException;
import com.here.xyz.util.service.errors.DetailedHttpException;
import com.here.xyz.util.service.rest.TooManyRequestsException;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
Expand Down Expand Up @@ -392,7 +393,8 @@ private void validateResponsePayload(Marker marker, final Typed payload) throws
10000 }
if (payload instanceof ErrorResponse) {
ErrorResponse errorResponse = (ErrorResponse) payload;
logger.warn(marker, "The connector {} [{}] responded with an error of type {}: {}", getConnector().id, (getConnector().getRemoteFunction()).getClass().getSimpleName() ,errorResponse.getError(),
String connectorType = (getConnector().getRemoteFunction()).getClass().getSimpleName();
logger.warn(marker, "The connector {} [{}] responded with an error of type {}: {}", getConnector().id, connectorType, errorResponse.getError(),
errorResponse.getErrorMessage());

switch (errorResponse.getError()) {
Expand All @@ -410,7 +412,7 @@ private void validateResponsePayload(Marker marker, final Typed payload) throws
case ILLEGAL_ARGUMENT:
throw new HttpException(BAD_REQUEST, errorResponse.getErrorMessage(), errorResponse.getErrorDetails());
case TIMEOUT:
throw new HttpException(GATEWAY_TIMEOUT, "Connector timeout error.", errorResponse.getErrorDetails());
throw new DetailedHttpException("E318541", Map.of("connectorId", getConnector().id, "connectorType", connectorType), errorResponse.getErrorDetails());
case EXCEPTION:
case BAD_GATEWAY:
throw new HttpException(BAD_GATEWAY, "Connector error.", errorResponse.getErrorDetails());
Expand Down Expand Up @@ -566,8 +568,10 @@ private HttpException getJsonMappingErrorMessage(final String stringResponse) {
Map<String, Object> response = XyzSerializable.deserialize(stringResponse, Map.class);
if (response.containsKey("errorMessage")) {
final String errorMessage = response.get("errorMessage").toString();
if (errorMessage.contains("timed out"))
return new HttpException(GATEWAY_TIMEOUT, "Connector timeout error.");
if (errorMessage.contains("timed out")) {
String connectorType = (getConnector().getRemoteFunction()).getClass().getSimpleName();
return new DetailedHttpException("E318541", Map.of("connectorId", getConnector().id, "connectorType", connectorType));
}
}
}
catch (Exception e) {
Expand Down
14 changes: 14 additions & 0 deletions xyz-hub-service/src/main/resources/hub-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,19 @@
"status": 405,
"cause": "The method is not allowed, because the resource ${resourceId} is marked as read-only.",
"action": "Update the resource definition to enable editing of features."
},
{
"title": "Connector timeout error.",
"code": "E318540",
"status": 504,
"cause": "Remote service did not respond within the expected time",
"action": "Please try again with a smaller region selection or reduce the amount of payload data to improve response time"
},
{
"title": "Connector timeout error.",
"code": "E318541",
"status": 504,
"cause": "The connector ${connectorId} [${connectorType}] responded with an error of type Timeout",
"action": "Please try again with a smaller region selection or reduce the amount of payload data to improve response time"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public class DetailedHttpException extends HttpException {
public final Map<String, String> placeholders;

public DetailedHttpException(String errorCode) {
this(errorCode, null, null);
this(errorCode, null, (Throwable) null);
}

public DetailedHttpException(String errorCode, Map<String, String> placeholders) {
this(errorCode, placeholders, null);
this(errorCode, placeholders, (Throwable) null);
}

public DetailedHttpException(String errorCode, Throwable cause) {
Expand All @@ -54,4 +54,13 @@ public DetailedHttpException(String errorCode, Map<String, String> placeholders,
put("cause", cause.getMessage());
}};
}

public DetailedHttpException(String errorCode, Map<String, String> placeholders, Map<String, Object> errorDetails) {
super(HttpResponseStatus.valueOf(getErrorDefinition(errorCode).getStatus()), getErrorDefinition(errorCode).composeMessage(placeholders), errorDetails);
this.errorDefinition = getErrorDefinition(errorCode);
this.placeholders = new HashMap<>() {{
if (placeholders != null)
putAll(placeholders);
}};
}
}
0