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

Fix koa ValidateError #1521

Merged
merged 2 commits into from
Dec 22, 2023
Merged

Fix koa ValidateError #1521

merged 2 commits into from
Dec 22, 2023

Conversation

hpx7
Copy link
Contributor

@hpx7 hpx7 commented Dec 16, 2023

Closes #1333

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you written unit tests?
  • Have you written unit tests that cover the negative cases (i.e.: if bad data is submitted, does the library respond properly)?
  • This PR is associated with an existing issue?

Closing issues

Put closes #XXXX (where XXXX is the issue number) in your comment to auto-close the issue that your PR fixes.

If this is a new feature submission:

  • Has the issue had a maintainer respond to the issue and clarify that the feature is something that aligns with the goals and philosophy of the project?

Potential Problems With The Approach

Test plan

I have verified this patch in my local tsoa + koa project

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there hpx7 👋

Thank you and congrats 🎉 for opening your first PR on this project.✨

We will review the following PR soon! 👀

@hpx7
Copy link
Contributor Author

hpx7 commented Dec 17, 2023

@WoH would you be able to provide any guidance on the testing strategy for this?

@hpx7
Copy link
Contributor Author

hpx7 commented Dec 17, 2023

The Koa Server (with noImplicitAdditionalProperties turned on) tests are failing on master for me, it doesn't seem related to this PR

@WoH
Copy link
Collaborator

WoH commented Dec 19, 2023

The Koa Server (with noImplicitAdditionalProperties turned on) tests are failing on master for me, it doesn't seem related to this PR

I think most of the invalid JSON errors are a consequence tbh.

@@ -92,7 +92,7 @@ export function RegisterRoutes(router: KoaRouter) {
} catch (err) {
const error = err as any;
context.status = error.status;
context.throw(error.status, JSON.stringify({ fields: error.fields }));
context.throw(context.status, error.message, error);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just rethrow, right?
And set expose to true:
https://github.com/koajs/koa/blob/master/docs/api/context.md#ctxthrowstatus-msg-properties

@hpx7
Copy link
Contributor Author

hpx7 commented Dec 19, 2023

@WoH I managed to track down and fix the tests

@hpx7
Copy link
Contributor Author

hpx7 commented Dec 20, 2023

The current test failures seem related to some dependency upgrade. yarn install && yarn test works but yarn install --no-lockfile && yarn test fails. Curiously, yarn list seems to give back the same output either way.

Any ideas @WoH?

EDIT: The failure is that the test expects GenericRequest_Array_ but is getting GenericRequest_global.Array_ for genericNestedArrayKeyword1 and genericNestedArrayKeyword2

@WoH
Copy link
Collaborator

WoH commented Dec 20, 2023

Yup, seems unrelated. I'll check what went wrong.

@hpx7
Copy link
Contributor Author

hpx7 commented Dec 22, 2023

Any luck so far @WoH ? Let me know if I can help

@WoH WoH merged commit 9c46f2a into lukeautry:master Dec 22, 2023
0 of 12 checks passed
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 this pull request may close these issues.

Can't catch ValidateError in Koa middleware
2 participants