api3dao / airnode

Airnode monorepo
https://docs.api3.org/
MIT License
165 stars 72 forks source link

Improve on-chain error message for failed API calls #1502

Closed dcroote closed 2 years ago

dcroote commented 2 years ago

Steps to reproduce

Run the coingecko integration in airnode-examples, but in integrations/coingecko/request-utils.ts replace Ethereum with Bthereum (or any other non-existent coin) as the coinLabel.

Present Behaviour

I performed the simple "mistake" listed above, which obviously caused the API call to fail. The on-chain fail tx errorMessage was, somewhat unhelpfully:

API call failed

Desired Behaviour

A user who make an error in the request could be provided with better on-chain error messages and Airnode has the ability to report more detailed errors, for example the below ERROR AxiosError: Request failed with status code 404. A 404 would be helpful as the user could then ask themselves why might the page not be found and re-check their request. Full log below:

[2022-10-24 06:50:02.261] INFO Created initial coordinator state                                                Coordinator-ID:0d74c006d6367893
[2022-10-24 06:50:02.265] INFO Forking to initialize providers                                                  Coordinator-ID:0d74c006d6367893
[2022-10-24 06:50:03.997] INFO Pending requests: 1 API call(s), 0 withdrawal(s)                                 Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider
[2022-10-24 06:50:04.330] INFO Forking to initialize providers complete                                         Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider
[2022-10-24 06:50:04.331] INFO Initialized EVM provider:exampleProvider                                         Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider
[2022-10-24 06:50:04.331] INFO Applying chain request limits                                                    Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider
[2022-10-24 06:50:04.338] INFO Applied chain request limits                                                     Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider
[2022-10-24 06:50:04.340] INFO Aggregated API calls                                                             Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider
[2022-10-24 06:50:06.345] ERROR Failed to call Endpoint:coinMarketData                                           Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:06.345] ERROR AxiosError: Request failed with status code 404
    at settle (/usr/local/share/.config/yarn/global/node_modules/axios/dist/node/axios.cjs:1268:12)
    at BrotliDecompress.handleStreamEnd (/usr/local/share/.config/yarn/global/node_modules/axios/dist/node/axios.cjs:2446:11)
    at BrotliDecompress.emit (events.js:412:35)
    at BrotliDecompress.emit (domain.js:475:12)
    at endReadableNT (internal/streams/readable.js:1333:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:06.346] INFO Processing 1 pending API call(s)...                                              Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:06.347] ERROR API call to Endpoint:coinMarketData errored after 2000ms with error message:API call failed Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:06.347] INFO Received 0 successful API call(s)                                                Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:06.347] INFO Received 1 errored API call(s)                                                   Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:06.355] INFO Executed API calls                                                               Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:06.357] INFO Disaggregated API calls                                                          Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:06.359] INFO Forking to submit transactions for EVM provider: exampleProvider and sponsor: 0x2E103c7502c1cAd0c11404F17D7C6339Db65626f... Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4
[2022-10-24 06:50:07.578] INFO Strategy (latestBlockPercentileGasPrice) gas price set to 13.337406323 gwei.     Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4, Sponsor-Address:0x2E103c7502c1cAd0c11404F17D7C6339Db65626f
[2022-10-24 06:50:07.923] INFO Submitting API call fail for Request:0x00f719b3a36ff1aa31688850eada14fe4061a5c712d681350d39ba17e1d874c3... Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4, Sponsor-Address:0x2E103c7502c1cAd0c11404F17D7C6339Db65626f
[2022-10-24 06:50:07.923] INFO Transaction:0x4c76b38e61f538dccc164a094c9ccca013ec6a474ffd7e025ea94e25d57a2ad5 submitted for Request:0x00f719b3a36ff1aa31688850eada14fe4061a5c712d681350d39ba17e1d874c3 Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4, Sponsor-Address:0x2E103c7502c1cAd0c11404F17D7C6339Db65626f
[2022-10-24 06:50:07.937] INFO Forking to submit transactions complete                                          Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4, Sponsor-Address:0x2E103c7502c1cAd0c11404F17D7C6339Db65626f
[2022-10-24 06:50:07.939] INFO Coordinator completed at 2022-10-24 06:50:07. Total time: 5679ms                 Coordinator-ID:0d74c006d6367893, Chain-ID:5, Provider:exampleProvider, Endpoint-ID:0xfb87102cdabadf905321521ba0b3cbf74ad09c5d400ac2eccdbef8d6143e78c4, Sponsor-Address:0x2E103c7502c1cAd0c11404F17D7C6339Db65626f
bbenligiray commented 2 years ago

Note that we decided not to relay the API error message back in the day because these sometimes include sensitive information. Relaying the status code is fine though.

martinkolenic commented 2 years ago

Test 1: Check for status code messages Environment: local eth node, local Airnode, beeceptor API response mocking

Steps: Modify the coingecko example to send requests to a mock Beeceptor endpoint, set up the endpoint to return the 404 code for any request; make request with the local Airnode; change to another code and repeat the request

Expected result: Receive more informative error messages for status codes 404, 301, 403 and 409 Actual result: Matches expected results

Test 2: Check for timeout message presence Environment: local eth node, local Airnode, beeceptor API response mocking

Steps: Modify the coingecko example to send requests to a mock Beeceptor endpoint, set up the endpoint to return a 200 code with a 600 second response; make request with the local Airnode; wait if the request times out

Expected result: Receive a timeout message Actual result: Matches expected results