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.

One request, two responses

See original GitHub issue

HI guys,

I’m facing an issue since yesterday that I can’t solve by myself so I’m asking your help since I don’t know if it’s a bug or not.

I use apisauce v0.14.0 + react 16.0.0-alpha.6 + react-native 0.44.3 + redux-saga 0.15.3

I added some logs in addRequestTransform and addResponseTransform

From a saga, I call an endpoint from my API. I can see the right data passing by addRequestTransform and a correct response passing by addResponseTransform. The exact response I’m waiting for.

BUT I’ve a second response passing by addResponseTransform with a weird data:

{
    duration: 89,
    problem: 'UNKNOWN_ERROR',
    ok: false,
    status: null,
    headers: null,
    config: null,
    data: null
}

and so, that’s the response received and processed by the saga which brings an unprocessable response.

When I google for UNKNOWN_ERROR the only occurence I find is in apisauce source code.

Does anyone has any idea of what could bring me to this error code?

Thanks for your help

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jmeisscommented, Jul 4, 2017

The AsyncStorage code is in the following saga when I fetch the device token with yield call(PushNotification.getDeviceToken)

export function * registerDevice (api) {
  yield call(PushNotification.requestPermissions)

  const token = yield call(PushNotification.getDeviceToken)
  const appVersion = DeviceInfo.getVersion()
  const lang = DeviceInfo.getDeviceLocale().substr(0, 2)
  const deviceUuid = DeviceInfo.getUniqueID()
  const devicePlatform = Platform.OS
  const deviceVersion = DeviceInfo.getSystemVersion()
  const deviceModel = DeviceInfo.getModel()
  const deviceManufacturer = DeviceInfo.getManufacturer()

  const response = yield call(api.registerDevice,
    appVersion,
    token,
    lang,
    deviceUuid,
    devicePlatform,
    deviceVersion,
    deviceModel,
    deviceManufacturer
  )

  if (response.ok) {
    yield put(NotificationActions.registerDeviceSuccess())
  } else {
    yield put(NotificationActions.registerDeviceFailure())
  }
}

Do you have more than one request transform? => yes, I’ve that one, scaffolded by ignite

  // Wrap api's addMonitor to allow the calling code to attach
  // additional monitors in the future.  But only in __DEV__ and only
  // if we've attached Reactotron to console (it isn't during unit tests).
  if (__DEV__ && console.tron) {
    apiConfig.addMonitor(console.tron.apisauce)
  }

and one that I created:

  apiMonitor: (response) => {
    const { duration, problem, status, headers, config, data } = response
    const methodName = config.method ? config.method.toUpperCase() : ''
    const error = new Error(`HTTP Error ${status} - ${methodName} ${config.url}`)

    if (STATUS_CODE_TO_NOT_CATCH.includes(status)) {
      return null
    }

    console.tron.log(`Bugsnag.notify: ${error}`)
    client.notify(error, (report) => {
      report.metadata = {
        request: {
          method: methodName,
          url: config.url,
          headers: config.headers,
          data: config.data,
          params: config.params
        },
        response: {
          status,
          headers,
          data,
          problem,
          duration: `${duration}ms`
        }
      }
    })
  }

Is there more than one listener to the REGISTER_DEVICE_REQUEST action? => nope

The current state of my inspection is:

  • the double async storage event is due to REDUX_PERSIST which is enabled. If I disable it, I only have the event once
  • When I remove the following condition from addResponseTransform, the response is on success and I’ve no UNKNOWN_ERROR triggered:
if (response &&
        response.headers &&
        !response.headers['content-type'].includes(response.config.headers['Accept'])) {
      return null
    }

this condition is used to avoid transform if I’m fetching our API v0 I will add a specific header to do a better check

0reactions
jmeisscommented, Jul 4, 2017

Oki, I will search into that direction. Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

sending two responses for same request - Stack Overflow
You can't send two responses to the same request. You can only send one fully formed response per request. That's the http specification....
Read more >
Sending multiple responses to single request | Service ...
Hi All, I have a requirement where i wanted to send multiple responses to a single request.For example I have request holdings_request1 and ......
Read more >
One HTTP request, two responses? - Super User
One of the API calls I make causes strange behaviour where it seems one HTTP request returns two HTTP responses.
Read more >
BPEL - One Request Multiple Responses - Tutorialspoint
In this chapter, we will learn about the concept of One Request and Multiple Responses. The Client BPEL Process sends a single request...
Read more >
Single request, multiple responses - legal? - Google Groups
Over a request-response protocol, the stream of JSON responses is just a single HTTP response. As far as HTTP is concerned, sending 10...
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