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

HttpErrorResponse status 0 on 401 error due to missing Origin header in Angular #1299

Open
mrmoein opened this issue Jan 21, 2025 · 0 comments

Comments

@mrmoein
Copy link

mrmoein commented Jan 21, 2025

Description: When making an HTTP request that results in a 401 Unauthorized error in Angular, the HttpErrorResponse status is returned as 0 instead of 401. This issue occurs when the Origin header is missing from the request. Although the Origin header is configured, it is not applied correctly in the case of the 401 error.

Solution: Adding the following middleware to the backend resolves the issue:

app.UseAuthentication();
app.UseAuthorization();

Once this is added, the Origin header is correctly applied, and the 401 error status is properly returned in the Angular application.

Expected Behavior: The Origin header should be included and properly applied to the request. The HttpErrorResponse should show a 401 status when an unauthorized request is made.

Actual Behavior: The Origin header is not applied, and the status code in the error response is 0.

Additional Question: Is adding this middleware (app.UseAuthentication(); and app.UseAuthorization();) safe, or does it introduce unnecessary overhead to the application?

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

1 participant