-
-
Notifications
You must be signed in to change notification settings - Fork 969
Closed
Labels
Description
Describe the bug
- Node.js version: v12.14.0
- OS & version: OSx Catalina
When trying to make an API call, I am getting the following error: (node:73533) UnhandledPromiseRejectionWarning: TypeError: The
url option cannot be used if the input is a valid URL.
. When I copy and paste the exact URL being tried into Postman, it works fine
Actual behavior
The error is being thrown and the API call is not being made.
...
Expected behavior
The API would be made.
...
Code to reproduce
Unfortunately, I cannot give an entirely repoduceable code snippet, because it requires a personal API key, but I believe the problem happens before the request is actually made. This is the code used to made the call:
getSummonerBySummonerId(summonerId: string): Promise<any> {
return got(
encodeURI(
'https://na1.api.riotgames.com/lol/summoner/v4/summoners/xWheQXcH0U1J20HleXa5dFJ137QleMldaJtSCxHK9ljsnKAv',
),
lolApiConstants.httpOptions,
);
}
const lolApiConstants = {
baseURL: 'https://na1.api.riotgames.com',
httpOptions: {
headers: {
'content-type': 'application/json',
'X-Riot-Token': process.env.LOL_API_KEY,
},
responseType: 'json',
resolveBodyOnly: true,
},
};
(node:73533) UnhandledPromiseRejectionWarning: TypeError: The `url` option cannot be used if the input is a valid URL.
at Object.exports.normalizeArguments (/Users/blubberbo/Web Projects/Lol-Pickem/lol-pickem-api/node_modules/got/dist/source/normalize-arguments.js:241:23)
at got (/Users/blubberbo/Web Projects/Lol-Pickem/lol-pickem-api/node_modules/got/dist/source/create.js:52:58)
at LolApiService.getSummonerBySummonerId (/Users/blubberbo/Web Projects/Lol-Pickem/lol-pickem-api/src/services/lol-api.service.ts:54:12)
at GameService.<anonymous> (/Users/blubberbo/Web Projects/Lol-Pickem/lol-pickem-api/src/services/game.service.ts:31:8)
at Generator.next (<anonymous>)
at fulfilled (/Users/blubberbo/Web Projects/Lol-Pickem/lol-pickem-api/dist/services/game.service.js:5:58)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:73533) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:73533) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Checklist
- [x ] I have read the documentation.
- [x ] I have tried my code with the latest version of Node.js and Got.
mpern