Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning on Server side #38

Closed
gtolarc opened this issue Oct 17, 2019 · 4 comments
Closed

UnhandledPromiseRejectionWarning on Server side #38

gtolarc opened this issue Oct 17, 2019 · 4 comments

Comments

@gtolarc
Copy link

gtolarc commented Oct 17, 2019

If I use useAxios on nextjs server side, if the call returns an error, an unhandled promise error will occur.
Is there any error handling in the execution of the ssrPromises array?

(node:73458) UnhandledPromiseRejectionWarning: Error: Request failed with status code 401
    at createError (/Users/mk/dev/workspace/dapps/gione/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/mk/dev/workspace/dapps/gione/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/Users/mk/dev/workspace/dapps/gione/node_modules/axios/lib/adapters/http.js:237:11)
    at IncomingMessage.emit (events.js:215:7)
    at IncomingMessage.EventEmitter.emit (domain.js:476:20)
    at endReadableNT (_stream_readable.js:1183:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
(node:73458) 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: 7)
(node:73458) [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.
@simoneb
Copy link
Owner

simoneb commented Oct 18, 2019

There currently isn't, as you can see here

axios-hooks/src/index.js

Lines 36 to 44 in 9f5a6ce

export async function serializeCache() {
const ssrPromisesCopy = [...ssrPromises]
ssrPromises.length = 0
await Promise.all(ssrPromisesCopy)
return cache.dump()
}

What would be a reasonable thing to do? I guess not much except swallowing the exception.

@gtolarc
Copy link
Author

gtolarc commented Oct 18, 2019

I think I misjudged the point where the error message appeared.

ssrPromises.push(axiosInstance({ ...config, adapter: cacheAdapter }))

Even though this code is executed on the server side even if it is option:manual.
Could you modify it to exclude if option:manual? @simoneb

@simoneb
Copy link
Owner

simoneb commented Oct 18, 2019

yeah there's definitely a bug there. wanna send a PR perhaps? (with tests please)

@simoneb
Copy link
Owner

simoneb commented Oct 19, 2019

The bug with manual requests being executed on the server is now addresses in version 1.4.1

@simoneb simoneb closed this as completed Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants