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

Returning async KakapoResponse in route handler breaks #178

Open
zzarcon opened this issue Feb 27, 2020 · 0 comments
Open

Returning async KakapoResponse in route handler breaks #178

zzarcon opened this issue Feb 27, 2020 · 0 comments

Comments

@zzarcon
Copy link
Member

zzarcon commented Feb 27, 2020

We have an issue currently in our fetchinterceptor, in where if we return a promise of a KakapoResponse it won't actually return the response body in the handler. That happens here

const response = handler(request, db);

if (response instanceof Promise) {
  //TODO: Should we handle 'requestDelay' also for async responses?
  return response.then(data => fakeResponse(data));
}

if (!(response instanceof KakapoResponse)) {
  return new Promise(resolve =>
    setTimeout(
      () => resolve(fakeResponse(response)),
      interceptor.getDelay()
    )
  );
}

const result = fakeResponse(response.body, response.headers);
return new Promise((resolve, reject) =>
  setTimeout(() => {
    if (response.error) {
      return reject(result);
    }
    return resolve(result);
  }, interceptor.getDelay())
);

After checking if the response it's a promise, we should also check if it's a KakapoResponse one, and handle it accordingly as we do:

const result = fakeResponse(response.body, response.headers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant