interledger / rafiki

An open-source, comprehensive Interledger service for wallet providers, enabling them to provide Interledger functionality to their users.
https://rafiki.dev/
Apache License 2.0
226 stars 77 forks source link

feat(backend): adding OpenPaymentsServerRouteError #2635

Closed mkurapov closed 2 months ago

mkurapov commented 2 months ago

Changes proposed in this pull request

Context

Work toward #1905

Checklist

netlify[bot] commented 2 months ago

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
BlairCurrey commented 2 months ago

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?

image

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/objection@3.1.4_knex@3.1.0/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:164:15\n    at Array.reduce (<anonymous>)\n    at convertPlainObject (/home/rafiki/node_modules/.pnpm/objection@3.1.4_knex@3.1.0/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:159:27)\n    at /home/rafiki/node_modules/.pnpm/objection@3.1.4_knex@3.1.0/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:69:14\n    at Array.map (<anonymous>)\n    at convertArgs (/home/rafiki/node_modules/.pnpm/objection@3.1.4_knex@3.1.0/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:57:15)\n    at KnexOperation.getKnexArgs (/home/rafiki/node_modules/.pnpm/objection@3.1.4_knex@3.1.0/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:19:12)\n    at KnexOperation.onBuildKnex (/home/rafiki/node_modules/.pnpm/objection@3.1.4_knex@3.1.0/node_modules/objection/lib/queryBuilder/operations/KnexOperation.js:8:59)\n    at PaginationQueryBuilder.callOperationMethod (/home/rafiki/node_modules/.pnpm/objection@3.1.4_knex@3.1.0/node_modules/objection/lib/queryBuilder/QueryBuilderOperationSupport.js:382:33)\n    at /home/rafiki/node_modules/.pnpm/objection@3.1.4_knex@3.1.0/node_modules/objection/lib/queryBuilder/QueryBuilderOperationSupport.js:489:37"
  },
  "msg": "Received unhandled error in Open Payments request"
}
mkurapov commented 2 months ago

@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"}