N
Nuxt23h ago
Brys

Nuxt Server crashes on production when a request fails.

Is there a reason on production when the server encounters an error it crashes? This behaviour does not follow what i would expect for an error not being fatal.
shad | 2106 | __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
shad | 2107 | return value;
shad | 2108 | };
shad | 2109 | class H3Error extends Error {
shad | 2110 | constructor(message, opts = {}) {
shad | 2111 | super(message, opts);
shad | ^
shad | error: A request couldn't complete
shad | cause: {
shad | "fatal": false,
shad | "statusCode": 401,
shad | "statusMessage": "A request couldn't complete",
shad | "data": "[GET] \"\": 401 Unauthorized",
shad | "stack": "Error: [GET] \"\": 401 Unauthorized\n at new H3Error (/usr/src/app/server/index.mjs:2111:5)\n at createError$1 (/usr/src/app/server/index.mjs:2144:19)\n at createError (/usr/src/app/server/chunks/build/server.mjs:358:21)\n at <anonymous> (/usr/src/app/server/chunks/build/server.mjs:1507:31)\n at processTicksAndRejections (native:7:39)"
shad | }
shad |
shad | at new H3Error (/usr/src/app/server/index.mjs:2111:5)
shad | at createError$1 (/usr/src/app/server/index.mjs:2240:14)
shad | at createError (/usr/src/app/server/chunks/build/server.mjs:415:32)
shad | at /usr/src/app/server/chunks/build/server.mjs:1748:25
shad | at processTicksAndRejections (native:7:39)
shad | 2106 | __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
shad | 2107 | return value;
shad | 2108 | };
shad | 2109 | class H3Error extends Error {
shad | 2110 | constructor(message, opts = {}) {
shad | 2111 | super(message, opts);
shad | ^
shad | error: A request couldn't complete
shad | cause: {
shad | "fatal": false,
shad | "statusCode": 401,
shad | "statusMessage": "A request couldn't complete",
shad | "data": "[GET] \"\": 401 Unauthorized",
shad | "stack": "Error: [GET] \"\": 401 Unauthorized\n at new H3Error (/usr/src/app/server/index.mjs:2111:5)\n at createError$1 (/usr/src/app/server/index.mjs:2144:19)\n at createError (/usr/src/app/server/chunks/build/server.mjs:358:21)\n at <anonymous> (/usr/src/app/server/chunks/build/server.mjs:1507:31)\n at processTicksAndRejections (native:7:39)"
shad | }
shad |
shad | at new H3Error (/usr/src/app/server/index.mjs:2111:5)
shad | at createError$1 (/usr/src/app/server/index.mjs:2240:14)
shad | at createError (/usr/src/app/server/chunks/build/server.mjs:415:32)
shad | at /usr/src/app/server/chunks/build/server.mjs:1748:25
shad | at processTicksAndRejections (native:7:39)
2 Replies
kapa.ai
kapa.ai23h ago
Hi @Brys. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, I can address your question about Nuxt server crashes on production when a request fails. The behavior you're experiencing, where the server crashes on a non-fatal error, is not the expected behavior for Nuxt 3. According to the Error Handling documentation (https://nuxt.com/docs/getting-started/error-handling), Nuxt provides mechanisms to handle errors without crashing the server. However, there are a few points to consider: 1. Error Handling: Nuxt 3 provides built-in error handling capabilities. You can use the createError function to create errors with specific status codes and messages. These errors should be handled gracefully without crashing the server. 2. Error Page: Nuxt allows you to customize the error page by adding an error.vue file in your project. This page should be displayed for errors instead of crashing the server. As mentioned in the Error Page documentation (https://nuxt.com/docs/getting-started/error-handling#error-page), "When Nuxt encounters a fatal error (any unhandled error on the server, or an error created with fatal: true on the client) it will either render a JSON response (if requested with Accept: application/json header) or trigger a full-screen error page." 3. Recent Changes: There have been recent updates to error handling in Nuxt. For example, a recent pull request (https://github.com/nuxt/nuxt/pull/28156) aimed to hide unhandled error messages in production for security reasons. Given the stack trace you provided, it seems that the error is being created (possibly using createError), but it's not being handled properly, leading to the server crash. This could be due to a few reasons: 1. Misconfiguration in your error handling setup. 2. A bug in your application code that's not properly catching or handling the error. 3. A potential issue with the version of Nuxt you're using. To address this issue, you could try the following: 1. Ensure you have proper error handling set up in your Nuxt application, including an error.vue page. 2. Check if you're using the latest stable version of Nuxt, as there have been improvements to error handling in recent versions. 3. Review your server-side code, especially around authentication (given the 401 status), to ensure errors are being properly caught and handled. 4. If the issue persists, it might be worth creating a minimal reproduction of the problem and reporting it as an issue on the Nuxt GitHub repository (https://github.com/nuxt/nuxt). Remember, non-fatal errors should not crash your Nuxt server in production. If they do, it's likely due to either a configuration issue or a potential bug that needs to be addressed. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai23h ago
<@443166863996878878> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?