Skip to content

Commit 4bb5ca4

Browse files
committed
fix: HTTP+JSON transport returns 501 instead of 400 for UnsupportedOperationError.
Returning the proper satuts code. Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
1 parent c12888d commit 4bb5ca4

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

transport/rest/src/main/java/io/a2a/transport/rest/handler/RestHandler.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -764,33 +764,42 @@ private static int mapErrorToHttpStatus(A2AError error) {
764764
return errorCode.httpCode();
765765
}
766766
if (error instanceof InvalidParamsError) {
767-
return 422;
767+
return A2AErrorCodes.INVALID_PARAMS.httpCode();
768768
}
769-
if (error instanceof MethodNotFoundError || error instanceof TaskNotFoundError) {
770-
return 404;
769+
if (error instanceof MethodNotFoundError) {
770+
return A2AErrorCodes.METHOD_NOT_FOUND.httpCode();
771+
}
772+
if (error instanceof TaskNotFoundError) {
773+
return A2AErrorCodes.TASK_NOT_FOUND.httpCode();
771774
}
772775
if (error instanceof TaskNotCancelableError) {
773-
return 409;
776+
return A2AErrorCodes.TASK_NOT_CANCELABLE.httpCode();
774777
}
775778
if (error instanceof UnsupportedOperationError) {
776-
return 501;
779+
return A2AErrorCodes.UNSUPPORTED_OPERATION.httpCode();
777780
}
778781
if (error instanceof ContentTypeNotSupportedError) {
779-
return 415;
782+
return A2AErrorCodes.CONTENT_TYPE_NOT_SUPPORTED.httpCode();
780783
}
781784
if (error instanceof InvalidAgentResponseError) {
782-
return 502;
785+
return A2AErrorCodes.INVALID_AGENT_RESPONSE.httpCode();
786+
}
787+
if (error instanceof ExtendedAgentCardNotConfiguredError) {
788+
return A2AErrorCodes.EXTENDED_AGENT_CARD_NOT_CONFIGURED.httpCode();
789+
}
790+
if (error instanceof ExtensionSupportRequiredError) {
791+
return A2AErrorCodes.EXTENSION_SUPPORT_REQUIRED.httpCode();
792+
}
793+
if (error instanceof VersionNotSupportedError) {
794+
return A2AErrorCodes.VERSION_NOT_SUPPORTED.httpCode();
783795
}
784-
if (error instanceof ExtendedAgentCardNotConfiguredError
785-
|| error instanceof ExtensionSupportRequiredError
786-
|| error instanceof VersionNotSupportedError
787-
|| error instanceof PushNotificationNotSupportedError) {
788-
return 400;
796+
if (error instanceof PushNotificationNotSupportedError) {
797+
return A2AErrorCodes.PUSH_NOTIFICATION_NOT_SUPPORTED.httpCode();
789798
}
790799
if (error instanceof InternalError) {
791-
return 500;
800+
return A2AErrorCodes.INTERNAL.httpCode();
792801
}
793-
return 500;
802+
return A2AErrorCodes.INTERNAL.httpCode();
794803
}
795804

796805
/**

0 commit comments

Comments
 (0)