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.

DefaultAdapter returns unknown/undefined by default

See original GitHub issue

Describe the bug The Default Adapter returns with out being set if the if/elseif isn’t met. This means an axios call (through AWS Amplify API) in nextJS getInitialProps throws because “Adapter is not a function”

To Reproduce Make a next js project with amplify and init with api. GraphQL uses axios to make the calls. Tracing the stack shows that the axios defaults module does not set the adapter.

Expected behavior The adapter should be set.

Environment:

  • Axios Version 0.19.0
  • OS: MacOs
  • Browser Chrome
  • Additional Library Versions Next 9.1.1

Additional context/Screenshots

function getDefaultAdapter() {
  var adapter;
  // Only Node.JS has a process variable that is of [[Class]] process
  if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
    // For node use HTTP adapter
    adapter = require('./adapters/http');
  } else if (typeof XMLHttpRequest !== 'undefined') {
    // For browsers use XHR adapter
    adapter = require('./adapters/xhr');
  }
  return adapter;
}

This is the method. The “Object.prototype.toString.call(process) === ‘[object process]’” is false because the process in nextJS is “‘[object Object]’”

This isn’t just an issue with nextJS. An if/elseif should never, imo, fall-through and return a variable that hasn’t been set. Throw from there or set a default in an else block.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:18

github_iconTop GitHub Comments

3reactions
flatherskevincommented, Nov 5, 2019

Any reason this issue is closed with the PR still open? I am experiencing the same issue with the adapter not being set while using AWS Amplify

1reaction
aliankaralicommented, Dec 6, 2019

Still having this issue with @aws-amplify/api@2.1.1 on server side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do functions return `undefined` instead of `null` by default?
The specification says of null and undefined : undefined value. primitive value used when a variable has not been assigned a value.
Read more >
Snapshot - 4.0 - Ember API Documentation
A snapshot or ID of a known relationship or null if the relationship is known but unset. undefined will be returned if the...
Read more >
_vue__webpack_imported_mod...
axios/axiosDefaultAdapter returns unknown/undefined by default#2507. Created about 3 years ago. 18. Describe the bug The Default Adapter returns with out ...
Read more >
Configuring Rails Applications - Rails Edge Guides
config.load_defaults loads default configuration values for a target version and all ... Rescues any exception returned by the application and renders nice ...
Read more >
Phalcon\Config
Returns a value from current config using a dot separated path. <?php echo $config->path("unknown.path", "default", "."); Copy. public get (mixed $index, ...
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