DefaultAdapter returns unknown/undefined by default
See original GitHub issueDescribe 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:
- Created 4 years ago
- Reactions:1
- Comments:18
Top GitHub Comments
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
Still having this issue with
@aws-amplify/api@2.1.1
on server side.