unjs / ipx

🖼️ High performance, secure and easy-to-use image optimizer.
MIT License
1.87k stars 63 forks source link

Handle fetch errors #154

Closed SagnikPradhan closed 11 months ago

SagnikPradhan commented 1 year ago

Describe the feature

Rather than throwing the fetch error and causing an unhandled exception, it should handle the error and return an error response.

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11457:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at process.processImmediate (node:internal/timers:449:9)
    at async Object.http (/home/.../packages/server/node_modules/ipx/dist/index.cjs:141:22)
    at async _handleRequest (/home/.../packages/server/node_modules/ipx/dist/index.cjs:567:18) {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (/home/.../packages/server/node_modules/next/dist/compiled/undici/index.js:1:82152)
      at /home/.../packages/server/node_modules/next/dist/compiled/undici/index.js:1:81644
      at Immediate._onImmediate (/home/.../packages/server/node_modules/next/dist/compiled/undici/index.js:1:82034)
      at process.processImmediate (node:internal/timers:478:21) {
    code: 'UND_ERR_CONNECT_TIMEOUT'
  }
}

Additional information

pi0 commented 11 months ago

Hi. Fetch errors should be slighly better in next major version (v2) with location details.