betagouv / preuve-covoiturage

Registre de preuve de covoiturage
https://app.covoiturage.beta.gouv.fr
Apache License 2.0
33 stars 12 forks source link

fix AJV error type #2466

Closed jonathanfallon closed 5 months ago

jonathanfallon commented 5 months ago

return InvalidParamsException when AJV fails

Summary by CodeRabbit

coderabbitai[bot] commented 5 months ago

Walkthrough

The recent changes focus on streamlining error handling, enhancing code readability, and improving error message consistency across the codebase. These updates aim to make the code more maintainable and easier to debug by refining error logging, reordering imports, adjusting function names, and updating error messages for clarity.

Changes

Files Changes Summary
.../validator/AjvValidator.ts, .../validator/ValidatorMiddleware.ts Reordered imports, added InvalidParamsException, updated error handling, introduced mapErrors, and simplified error handling.
.../services/acquisition/actions/CreateJourneyAction.spec.ts, .../services/acquisition/actions/CreateJourneyAction.ts Reordered imports, adjusted function names, fixed typos, added logging, and refined error messages.
.../services/cee/actions/ImportCeeAction.integration.spec.ts, .../services/cee/actions/ImportCeeAction.ts Reordered imports, moved declarations, adjusted error message checks, and improved error message structure.
.../services/cee/actions/ImportCeeIdentityAction.integration.spec.ts Reordered imports, updated import order, adjusted declarations, and modified error message access in test cases.
.../services/cee/actions/RegisterCeeAction.integration.spec.ts Reordered imports, adjusted error message formatting, and updated error data handling in test cases.
.../services/cee/actions/SimulateCeeAction.integration.spec.ts Updated error message formatting in test assertions, removed a logging statement, and improved error handling.
shared/cee/common/ceeSchema.ts Updated error messages for various schemas related to phone numbers, driving licenses, timestamps, IDs, and status for clarity and consistency.

🐇 Poem by CodeRabbit

In the realm of code where the rabbits play,
Errors vanish as they bounce away.
Lines now shine with a polished sheen,
Debugging made easy, like a serene dream.
Let's dance in the code under the moon's soft light,
With each update, making our code bright! 🌟


Recent Review Details **Configuration used: CodeRabbit UI**
Commits Files that changed from the base of the PR and between b0c03a1b6ab95d5e899888e49d4bc68b051988b0 and b17ea30f9cf337cb51dc9a94194b4745287a20cc.
Files selected for processing (7) * api/src/ilos/validator/ValidatorMiddleware.ts (1 hunks) * api/src/pdc/services/cee/actions/ImportCeeAction.integration.spec.ts (6 hunks) * api/src/pdc/services/cee/actions/ImportCeeAction.ts (1 hunks) * api/src/pdc/services/cee/actions/ImportCeeIdentityAction.integration.spec.ts (6 hunks) * api/src/pdc/services/cee/actions/RegisterCeeAction.integration.spec.ts (11 hunks) * api/src/pdc/services/cee/actions/SimulateCeeAction.integration.spec.ts (5 hunks) * shared/cee/common/ceeSchema.ts (3 hunks)
Additional comments not posted (26)
api/src/ilos/validator/ValidatorMiddleware.ts (1)
`15-15`: Ensure that `InvalidParamsException` is properly imported and used here since the direct throwing of this exception is a significant change in error handling.
api/src/pdc/services/cee/actions/ImportCeeAction.ts (1)
`31-31`: The updated error message format for the `datetime` field enhances clarity and should help in debugging. Ensure that the `timestampSchema` is correctly defined with the `errorMessage` property.
shared/cee/common/ceeSchema.ts (4)
`29-29`: The updated error message for the `phoneTruncSchema` improves clarity. Ensure consistency across all schemas. --- `75-75`: The updated error message for the `drivingLicenseSchema` is clearer and more specific, which should help in validation error reporting. --- `82-82`: The error message for `timestampSchema` now clearly specifies the required format, which is beneficial for validation purposes. --- `91-91`: The error message for `operatorJourneyIdSchema` has been clarified. This is crucial for debugging and validation.
api/src/pdc/services/cee/actions/ImportCeeIdentityAction.integration.spec.ts (5)
`56-56`: The updated error message access in the test case ensures that specific validation errors are correctly captured and asserted. --- `66-66`: Correctly accessing the `lastNameTruncSchema.errorMessage` in the test ensures that specific error messages are used, which aids in precise testing. --- `76-76`: Using `ceeJourneyTypeEnumSchema.errorMessage` in the test case is a good practice as it ensures that the error messages are consistent with the schema definitions. --- `86-86`: The test case correctly uses `timestampSchema.errorMessage` for validation errors, which is crucial for maintaining consistency in error reporting. --- `96-96`: Accessing `phoneTruncSchema.errorMessage` in the test case ensures that the error messages are consistent and accurate.
api/src/pdc/services/cee/actions/ImportCeeAction.integration.spec.ts (5)
`57-57`: The updated error message access in the test case ensures that specific validation errors are correctly captured and asserted. --- `67-67`: Correctly accessing the `lastNameTruncSchema.errorMessage` in the test ensures that specific error messages are used, which aids in precise testing. --- `77-77`: Using `ceeJourneyTypeEnumSchema.errorMessage` in the test case is a good practice as it ensures that the error messages are consistent with the schema definitions. --- `87-87`: The test case correctly uses `timestampSchema.errorMessage` for validation errors, which is crucial for maintaining consistency in error reporting. --- `97-97`: Accessing `phoneTruncSchema.errorMessage` in the test case ensures that the error messages are consistent and accurate.
api/src/pdc/services/cee/actions/SimulateCeeAction.integration.spec.ts (4)
`82-82`: Updating the error message format in the test assertion for `last_name_trunc` improves clarity and consistency with schema definitions. --- `92-92`: The updated error message format for `journey_type` in the test assertion aligns with the schema and enhances error clarity. --- `102-102`: The error message format for `driving_license` in the test assertion is updated for better clarity and consistency. --- `112-112`: The test assertion for `phone_trunc` uses the updated error message format, ensuring consistency and clarity in error reporting.
api/src/pdc/services/cee/actions/RegisterCeeAction.integration.spec.ts (6)
`74-74`: The updated error message format for `last_name_trunc` in the test assertion improves clarity and consistency with schema definitions. --- `84-84`: The updated error message format for `journey_type` in the test assertion aligns with the schema and enhances error clarity. --- `94-94`: The error message format for `driving_license` in the test assertion is updated for better clarity and consistency. --- `104-107`: The test assertion for `operator_journey_id` uses the updated error message format, ensuring consistency and clarity in error reporting. The use of `t.deepEqual` for array comparison is appropriate here. --- `117-117`: The test assertion for `datetime` uses the updated error message format, ensuring consistency and clarity in error reporting. --- `127-127`: The test assertion for `phone_trunc` uses the updated error message format, ensuring consistency and clarity in error reporting.
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.