Skip to content
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

Return errors thrown in serDes serializers/deserializer #841

Closed
marcocastignoli opened this issue May 11, 2023 · 1 comment · Fixed by #936, #944, #951, #960 or #1008
Closed

Return errors thrown in serDes serializers/deserializer #841

marcocastignoli opened this issue May 11, 2023 · 1 comment · Fixed by #936, #944, #951, #960 or #1008

Comments

@marcocastignoli
Copy link
Contributor

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.

@marcocastignoli
Copy link
Contributor Author

I think the problem is here:

try {
ctx.parentData[ctx.parentDataProperty] = sch.deserialize(data);
} catch (e) {
validate.errors = [
{
keyword: 'serdes',
instancePath: ctx.instancePath,
schemaPath: it.schemaPath.str,
message: `format is invalid`,
params: { 'x-eov-req-serdes': ctx.parentDataProperty },
},
];
return false;
}

The catched error is completally lost

marcocastignoli added a commit to marcocastignoli/express-openapi-validator that referenced this issue May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment