question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addRequestTransform + addAsyncRequestTransform fail to fire immediately after browser refresh.

See original GitHub issue

I’m using apisauce in a web-based project and am noticing some unexpected behaviour in the api call immediately after a browser refresh. It seems that addRequestTransform or addAsyncRequestTransform do not stick in that scenario. Using 0.14.1.

Code below - It should look remarkably familiar. 😄

const create = () => {
  // ------
  // STEP 1
  // ------
  //
  // Create and configure an apisauce-based api object.
  //
  const api = apisauce.create({
    // base URL is read from the "constructor"
    baseURL,
    // here are some default headers
    headers: {
      accept: 'application/vnd.api+json',
      'content-type': 'application/vnd.api+json'
    },
    // 10 second timeout...
    timeout: 10000
  })

  api.addAsyncRequestTransform(request => async () => {
    api.setHeader('awesome-async-dude', 'Steve Kellock')
  })

  api.addRequestTransform(request => {
    api.setHeader('awesome-sync-dude', 'Gant Laborde')
  })

I’m looking on my back end and I can see that the headers are not set in the request immediately following the browser refresh, but from the next request onwards, they are present (both awesome-async-dude and awesome-sync-dude).

Strangely enough, If I console.log out the activity I see that both the methods are called during processing of all requests, but I am unsure of the order that they actually resolve (thanks, sync processing).

Is this weird, or have I missed something somewhere along the line?

PS. I’ve simplified the headers I am setting with the transform in an attempt to isolate the problem - I removed an async call to get an auth token, which makes far more sense!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
skellockcommented, Oct 15, 2017
api.addAsyncRequestTransform(request => async () => {
    api.setHeader('awesome-async-dude', 'Steve Kellock')
     request.headers[‘awesome-async-dude’] = ‘Steve Kellock’ // change the current request too
  })

Does something like that work?

0reactions
skellockcommented, Oct 16, 2017

Ya, it’s an awkward interface. Sorry for the confusion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to receive POST data unless I refresh client. why ...
I think I got the problem. In the react app, maybe you are not using e.preventDefault() when you click submit. The browser, by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found