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

Getting type error when accessing errorCode property of a ValidationErrorItem #679

Closed
shashanksapre opened this issue Dec 2, 2021 · 1 comment · Fixed by #819
Closed

Comments

@shashanksapre
Copy link

Describe the bug
Getting a type error when I try to access properties of errors array within an error object of type ValidationError

To Reproduce
Access the property errorCode inside an ValidationErrorItem

Actual behavior
Type error: Property 'errorCode' does not exist on type 'ValidationErrorItem'. Did you mean 'error_code'.
If I try to access error_code, it's undefined.

Expected behavior
Should be able to access errorCode as that's what is returned by express-openapi-validator
image

Examples and context
I'm trying to transform errors returned by validator into another standard error body response.

image

@konstantinblaesi
Copy link

I ran into the same issue, looks like the codebase uses a mix of both errorCode and error_code. As a workaround I declared

interface OpenAPIValidationError extends ValidationErrorItem {
    errorCode?: string
}

Using an express middleware I transform them like

const errorCode = err.error_code || err.errorCode || "unknown"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants