Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Error thrown from async routes not being handled #487

Closed
nikku opened this issue Oct 20, 2018 · 4 comments
Closed

Error thrown from async routes not being handled #487

nikku opened this issue Oct 20, 2018 · 4 comments
Labels

Comments

@nikku
Copy link
Contributor

nikku commented Oct 20, 2018

Starting from the sapper-template, suppose I change blog/index.json.js to the following:

export async function get(req, res) {
  throw new Error('OOPPPS');
}

Expected Behavior

  1. the error is caught, logged properly and indicated via a 500
  2. when rendering the route /blog server side a status code >= 400 triggers the appropriate error message to be rendered
  3. when prefetching or rendering the blog client-side the error page indicates a problem

Actual Behavior

An unhandled promise rejection error is being logged and the error is silently discarted:

(node:14150) UnhandledPromiseRejectionWarning: Unhandled promise rejection

Serving the request hangs forever (server-side rendering simply hangs).

Environment

sapper@0.23.3

nikku added a commit to nikku/sapper that referenced this issue Oct 20, 2018
@Rich-Harris
Copy link
Member

Closing, as this was fixed in #488

@nikku
Copy link
Contributor Author

nikku commented Oct 27, 2018

As mentioned here the issue is not 100% resolved. Should I open another issue suggesting follow up improvements?

Still remaining to be fixed:

Expected Behavior

  1. when rendering the route /blog server side a status code >= 400 triggers the appropriate error message to be rendered
  2. when prefetching or rendering the blog client-side the error page indicates a problem

@Rich-Harris
Copy link
Member

Ah, my bad. Yes, if you could that'd be very helpful, thanks

@carcinocron
Copy link

carcinocron commented Sep 7, 2019

for me, this:

{#await promise}
  <Loader />
{:then users }
   [...]
{:catch error}
  <ErrorAlert {error} />
{/await}

<script>
import api from '~/lib/api'
import ErrorAlert from '~/components/ErrorAlert.svelte'
import Loader from '~/components/global/Loader.svelte'

let promise

promise = fetch()

async function fetch () {
  return (await api.get(`/users`)).data
}
</script>

is throwing:

(node:27201) UnhandledPromiseRejectionWarning: Error: Request failed with status code 401
    at createError (/home/forge/code/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/home/forge/code/node_modules/axios/lib/core/settle.js:18:12)
    at IncomingMessage.handleStreamEnd (/home/forge/code/node_modules/axios/lib/adapters/http.js:202:11)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
(node:27201) 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:27201) [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.

when running yarn run export

but I can stop it by adding:

// does nothing, but stops UnhandledPromiseRejectionWarning in SSR
$: promise.catch(err => null)

even though I am expecting the {:catch error} to have caught it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants