feat(backend): adding OpenPaymentsServerRouteError
Changes proposed in this pull request
- Adding
OpenPaymentsServerRouteErrorthat is caught by a newopenPaymentsServerErrorMiddleware(this middleware runs as the last middleware), which will properly handle all of errors thrown in the Open Payments Resource Server routes. This means:- we wont ever need to use
ctx.throwin the routes, we just throwOpenPaymentsServerRouteErrorwhich will automatically be handled in the middleware - all logging is standardized for errors: response code + request body, other details are properly logged
- The new
@interledger/openapipackage exportsOpenAPIValidatorMiddlewareError, which is now also handled explicitly in the middleware
- we wont ever need to use
Context
Work toward #1905
Checklist
- [x] Related issues linked using
fixes #number - [x] Tests added/updated
- [ ] Documentation added
- [ ] Make sure that all checks pass
- [ ] Bruno collection updated
Deploy Preview for brilliant-pasca-3e80ec canceled.
| Name | Link |
|---|---|
| Latest commit | 57075f430a6cc4e2cd2043a3832e14fcff610e50 |
| Latest deploy log | https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/661e423a0bbd850008ca34d1 |
Is the open api request validation not working for you? I deleted the wallet address from the create incoming payment body in bruno and it makes it all the way to objection before erroring. I think the validator middleware should be picking this up first though?
I think the whole uncaught error path and log in the new middleware looks good though.
{
"level": 50,
"time": 1712859649461,
"pid": 1,
"hostname": "happy-life-bank-backend",
"method": "POST",
"path": "/incoming-payments",
"err": {
"type": "Error",
"message": "undefined passed as a property in argument #0 for 'where' operation. Call skipUndefined() method to ignore the undefined values.",
"stack": "Error: undefined passed as a property in argument #0 for 'where' operation. Call skipUndefined() method to ignore the undefined values.\n at /home/rafiki/node_modules/.pnpm/[email protected][email protected]/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:164:15\n at Array.reduce (<anonymous>)\n at convertPlainObject (/home/rafiki/node_modules/.pnpm/[email protected][email protected]/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:159:27)\n at /home/rafiki/node_modules/.pnpm/[email protected][email protected]/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:69:14\n at Array.map (<anonymous>)\n at convertArgs (/home/rafiki/node_modules/.pnpm/[email protected][email protected]/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:57:15)\n at KnexOperation.getKnexArgs (/home/rafiki/node_modules/.pnpm/[email protected][email protected]/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:19:12)\n at KnexOperation.onBuildKnex (/home/rafiki/node_modules/.pnpm/[email protected][email protected]/node_modules/objection/lib/queryBuilder/operations/KnexOperation.js:8:59)\n at PaginationQueryBuilder.callOperationMethod (/home/rafiki/node_modules/.pnpm/[email protected][email protected]/node_modules/objection/lib/queryBuilder/QueryBuilderOperationSupport.js:382:33)\n at /home/rafiki/node_modules/.pnpm/[email protected][email protected]/node_modules/objection/lib/queryBuilder/QueryBuilderOperationSupport.js:489:37"
},
"msg": "Received unhandled error in Open Payments request"
}
@BlairCurrey
That is coming from createWalletAddressMiddleware, which is called before the validator middleware.
Unfourtunatetly I still need to update createWalletAddressMiddleware to properly throw the new error type, but I was thinking of doing it in a separate PR since this already is getting a bit too big.
If you try changing, or passing an incorrect value for a different field, you should see the correct validation error:
{"level":30,"time":1712933544211,"pid":1,"hostname":"happy-life-bank-backend","method":"POST","path":"/incoming-payments","message":"Received error validating OpenAPI request: body must NOT have additional properties: sadfdsa","status":400,"msg":"Received OpenAPI validation error when handling Open Payments request"}