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

Vite dev server crashes when HttpClient receives non-200 code #58123

Closed
1 task done
zip-fa opened this issue Oct 6, 2024 · 7 comments · Fixed by angular/angular-cli#28405
Closed
1 task done

Vite dev server crashes when HttpClient receives non-200 code #58123

zip-fa opened this issue Oct 6, 2024 · 7 comments · Fixed by angular/angular-cli#28405
Labels
area: server Issues related to server-side rendering core: zoneless Issues related to running Angular without zone.js
Milestone

Comments

@zip-fa
Copy link

zip-fa commented Oct 6, 2024

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

v17

Description

Basically, it's a duplicate of angular/angular-cli#26192

But now it's here again with v19, zoneless and outputMode: 'server'.
Is this behaviour expected and not-an-issue on new setup?

Minimal Reproduction

ng serve

Exception or Error

No response

Your Environment

HttpErrorResponse

Anything else relevant?

No response

@alan-agius4
Copy link
Contributor

This is a known issue with zoneless, and it not limited to dev-servers.

@alan-agius4 alan-agius4 self-assigned this Oct 7, 2024
@zip-fa
Copy link
Author

zip-fa commented Oct 7, 2024

In prod env, server will crash too? Is there any catch error mechanism that can be applied to not stop dev/prod app, but respond with 500 code?

@alan-agius4
Copy link
Contributor

alan-agius4 commented Oct 7, 2024

Yes, in the production environment, the server will crash because zone.js is not intercepting and handling unhandled errors and rejections.

Since the error is "unhandled," the request's lifecycle will continue in this scenario. For a potential workaround, please refer to angular/angular-cli#28405

alan-agius4 referenced this issue in alan-agius4/angular-cli Oct 7, 2024
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes #28581
alan-agius4 referenced this issue in alan-agius4/angular-cli Oct 7, 2024
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes #28581
alan-agius4 referenced this issue in alan-agius4/angular-cli Oct 7, 2024
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes #28581
alan-agius4 referenced this issue in alan-agius4/angular-cli Oct 7, 2024
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes #28581
@alan-agius4
Copy link
Contributor

Moving to the FW repo as following the convo in angular/angular-cli#28405 (comment) the FW should handle the errors.

@alan-agius4 alan-agius4 transferred this issue from angular/angular-cli Oct 8, 2024
@alan-agius4 alan-agius4 added the core: zoneless Issues related to running Angular without zone.js label Oct 8, 2024
@alan-agius4 alan-agius4 removed their assignment Oct 8, 2024
@pkozlowski-opensource pkozlowski-opensource added the area: server Issues related to server-side rendering label Oct 23, 2024
@ngbot ngbot bot added this to the needsTriage milestone Oct 23, 2024
@patricsteiner
Copy link

patricsteiner commented Dec 9, 2024

This is quite annoying... Catching all node errors globally seems not to be the right solution, as discussed in angular/angular-cli#28405 (comment). Is there no recommended approach on how to handle these errors? For now I am using a global interceptor that just returns EMPTY on error. This is still quite bad, since it leaves the app in an unexpected state that likely needs a page refresh to work again, but at least the server does not crash.

export const httpErrorInterceptor: HttpInterceptorFn = (req, next) => {
  const toast = inject(ToastService)
  return next(req).pipe(
    catchError((err) => {
      console.error(err);
      toast.show("HTTP Error: " + err.message)
      return EMPTY;
    }),
  );
};

@zip-fa
Copy link
Author

zip-fa commented Dec 12, 2024

This is quite annoying... Catching all node errors globally seems not to be the right solution, as discussed in angular/angular-cli#28405 (comment). Is there no recommended approach on how to handle these errors? For now I am using a global interceptor that just returns EMPTY on error. This is still quite bad, since it leaves the app in an unexpected state that likely needs a page refresh to work again, but at least the server does not crash.

export const httpErrorInterceptor: HttpInterceptorFn = (req, next) => {
const toast = inject(ToastService)
return next(req).pipe(
catchError((err) => {
console.error(err);
toast.show("HTTP Error: " + err.message)
return EMPTY;
}),
);
};

Returning EMPTY or catching error project-wide will break rxResource. It’s better to move all your GET requests to rxResource and remove your project-wide error interceptor

@patricsteiner
Copy link

Returning EMPTY or catching error project-wide will break rxResource. It’s better to move all your GET requests to rxResource and remove your project-wide error interceptor

That would work I guess, but refactoring all http requestrs to use rxResource would be quite a hassle.

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Apr 1, 2025
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes angular/angular#58123
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Apr 1, 2025
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes angular/angular#58123
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Apr 1, 2025
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes angular/angular#58123
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Apr 3, 2025
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes angular/angular#58123
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Apr 4, 2025
Implement the `attachNodeGlobalErrorHandlers` function to handle 'unhandledRejection' and 'uncaughtException' events in Node.js. This function logs errors to the console, preventing unhandled errors from crashing the server. It is particularly useful for zoneless apps, ensuring error handling without relying on zones.

Closes angular/angular#58123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: server Issues related to server-side rendering core: zoneless Issues related to running Angular without zone.js
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants