openwallet-foundation / acapy

ACA-Py is a foundation for building decentralized identity applications and services running in non-mobile environments.
https://aca-py.org
Apache License 2.0
419 stars 512 forks source link

:sparkles: Handle NotFound and UnprocessableEntity errors in middleware #3327

Closed ff137 closed 2 weeks ago

ff137 commented 2 weeks ago

Closes #3322

Currently, NotFound and UnprocessableEntity errors would print stack traces in the logs. It is more sensible to record these as info logs, since they typically represent bad requests / client errors.

This PR contributes changes so that the new behaviour will print messages like:

Not Found error occurred during GET /connections/abe80270-051c-415b-9bb1-b74a86846276: Record not found: connection/abe80270-051c-415b-9bb1-b74a86846276
Unprocessable Entity occurred during GET /connections: {'querystring': {'their_public_did': ['Value None is not a valid DID']}}

A util method extract_validation_error_message was added to help print this marshmallow validation error, so that the logs still provide the error context previously contained in the stack trace.


:art: Other minor amendments included as well:

ff137 commented 2 weeks ago

5.0% Duplication on New Code (required ≤ 3%)

Can we increase this threshold to something more pragmatic? 10-20% would make sense

jamshale commented 2 weeks ago

5.0% Duplication on New Code (required ≤ 3%)

Can we increase this threshold to something more pragmatic? 10-20% would make sense

We can, but it's a bit of an annoying process because none of the maintainers have admin rights on the sonarcloud project right now. There is ways to set setting in the sonar-project.properties file and the github action but I haven't experimented much with this. For now I think we'll just have to comment when you think something should be ignored, but I would like to clean some of these reports up in the future.

sonarcloud[bot] commented 2 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
91.7% Coverage on New Code
0.7% Duplication on New Code

See analysis details on SonarCloud