Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"(node:20862) UnhandledPromiseRejectionWarning: FetchError: network timeout" when API answer exceeds predefined timeout #483

Closed
terradek opened this issue Jul 29, 2018 · 5 comments
Labels

Comments

@terradek
Copy link

Environment:
Frisby 2.1.0 (it works fine on 2.0.16), Node: v10.6.0, Ubuntu 18.04,

Test code snippet:
frisby.timeout(400) // or using .setup({request:{timeout: 400}}) .get(baseUrl+'~info').inspectResponse()

Full ERROR log:
(node:20862) UnhandledPromiseRejectionWarning: FetchError: network timeout at: https://dev.com:443/api/v1.1/~info at Timeout.<anonymous> (/home/and/Desktop/api-test/node_modules/node-fetch/lib/index.js:1338:13) at ontimeout (timers.js:427:11) at tryOnTimeout (timers.js:289:5) at listOnTimeout (timers.js:252:5) at Timer.processTimers (timers.js:212:10) (node:20862) UnhandledPromiseRejectionWarning: FetchError: network timeout at: https://dev.com:443/api/v1.1/~info warning.js:18 at Timeout.<anonymous> (/home/and/Desktop/api-test/node_modules/node-fetch/lib/index.js:1338:13) at ontimeout (timers.js:427:11) at tryOnTimeout (timers.js:289:5) at listOnTimeout (timers.js:252:5) at Timer.processTimers (timers.js:212:10)

PS thank you for development this very handy tool.

@terradek terradek changed the title "(node:20862) UnhandledPromiseRejectionWarning: FetchError: network timeout" when API answer exceeds timeout "(node:20862) UnhandledPromiseRejectionWarning: FetchError: network timeout" when API answer exceeds predefined timeout Jul 29, 2018
@H1Gdev
Copy link
Collaborator

H1Gdev commented Jul 30, 2018

@terradek

Please adjust Jasmine timeout in either way.(default: 5[ms])

  • set jasmine.DEFAULT_TIMEOUT_INTERVAL.
  • set 3rd argument in it().

https://jasmine.github.io/api/2.6/global.html#it

@terradek
Copy link
Author

terradek commented Aug 1, 2018

@H1Gdev Thanks for your answer.
I'm currently don't use Jasmine. I'm new to Frisby and JS, so my code is very simple:

`'use strict'
const frisby = require('frisby');
const Joi = frisby.Joi;
const baseUrl = 'https://dev.com:443/api/v1.1/';
const defaultJoiOptions = { convert: false, presence: "required" }

frisby.timeout(500) //.setup({request:{timeout: 300}})
.get(baseUrl+'~info').inspectResponse()
.inspectJSON()
.expect('jsonTypes', {
meta: Joi.object({
status: Joi.string().valid('ok').error(() => 'status must be: "ok"'),
error: Joi.equal(null)
}).options(defaultJoiOptions),
});`

And I see that timeout value is set as needed but when endpoint answer time exceeds timeout it throws this error.

@H1Gdev
Copy link
Collaborator

H1Gdev commented Aug 2, 2018

@terradek

I understood your runtime environment.

Frisby is test framework based on Promise.
If error is occured, catch myself or Event: 'unhandledRejection' is emitted.

Update your code.

'use strict'
const frisby = require('frisby');
const Joi = frisby.Joi;
const baseUrl = 'https://dev.com:443/api/v1.1/';
const defaultJoiOptions = { convert: false, presence: "required" }

frisby.timeout(500) //.setup({request:{timeout: 300}})
  .get(baseUrl+'~info')
  .inspectResponse()
  .inspectJSON()
  .expect('jsonTypes', {
    meta: Joi.object({
      status: Joi.string().valid('ok').error(() => 'status must be: "ok"'),
      error: Joi.equal(null)
    }).options(defaultJoiOptions),
  })
  .catch(err => { // <- add catch.
    // catch network timeout and Joi error.
    console.log('error', error.message);
  });

@H1Gdev H1Gdev added the Question label Aug 2, 2018
@H1Gdev
Copy link
Collaborator

H1Gdev commented Aug 20, 2018

@terradek

Did you solve this issue?

@vlucas
Copy link
Owner

vlucas commented Aug 22, 2018

If you return frisby.get(...) in your tests, the test framework automatically attaches .catch handlers and handles the failure cases. That is the recommended approach when using Frisby. If you always return the Promise in your tests, you will never have to do this manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants