Skip to content

Return errors thrown in serDes serializers/deserializer #841

Closed
@marcocastignoli

Description

@marcocastignoli

Describe the bug
The system is throwing an incorrect error message. Instead of the custom error message thrown in the serializer, the system is returning a generic OpenAPI validation error. Actually, I don't know if it is an intended feature or a bug.

To Reproduce

  1. Pass a chain argument to the serializer that is not supported for verification.
  2. The system returns an OpenAPI validation error instead of the custom error message.

Actual behavior
The system returns the following error message:

{
  "message": "request/body/chain format is invalid",
  "errors": [
    {
      "path": "/body/chain",
      "message": "format is invalid",
      "errorCode": "serdes.openapi.validation"
    }
  ]
}

Expected behavior
The system should return the custom error message thrown in the serializer:

Chain ${chain} not supported for verification!

Examples and context
Here's a snippet of the code of the serializer

//serDes
          {
            format: "supported-chains",
            deserialize: (chain: string) => checkSupportedChainId(chain),
            serialize: () => (chain: string) => chain,
          },

// checkSupportedChainId
export function checkSupportedChainId(chain: string): string {
  if (!(chain in sourcifyChainsMap && sourcifyChainsMap[chain].supported)) {
    throw new Error(`Chain ${chain} not supported for verification!`);
  }

  return chain;
}

This bug suggests that our error handling is not capturing and returning the appropriate messages from our application logic. Instead, it's defaulting to the more general OpenAPI validation error. We may need to check our error handling flow or how we're mapping application errors to our API responses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions