Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

An unhandled exception occurred while processing the request #1234

Closed
chamikasandamal opened this issue Aug 29, 2017 · 4 comments
Closed

An unhandled exception occurred while processing the request #1234

chamikasandamal opened this issue Aug 29, 2017 · 4 comments

Comments

@chamikasandamal
Copy link

I'm using dotnet core sdk 2.0 SPA template for angular. when running the application, i can see following error. This issue is there when it running through visual studio 2017 as well as when it published to azure.
But when i switch off the pre-rendering by removing asp-prerender-module="xxx", it is working fine.

WinHttpException: The connection with the server was terminated abnormally
Unknown location

IOException: The read operation failed, see inner exception.
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

HttpRequestException: Error while copying content to a stream.
System.Net.Http.HttpContent+<LoadIntoBufferAsyncCore>d__48.MoveNext()

Note: I'm using organizational account authentication

@SteveSandersonMS
Copy link
Member

Hi @chamikasandamal - could you please post specific repro steps? If I create a new Angular project, what are the minimal code changes that result in this issue?

@chamikasandamal
Copy link
Author

It seems following line of codes cause the issue. I had to check typeof window !== 'undefined' since it returns server time withe the pre-rendering. when i wrap the this.subscription.unsubscribe(); with same condition, error is gone.

    ngOnInit(): void {
        if (typeof window !== 'undefined') {            
            this.calculateTime();
            setInterval(() => {
                this.calculateTime();
            }, 1000);
        }
    }

    public ngOnDestroy(): void {
        this.subscription.unsubscribe(); //<-- this caused the issue
    }

Seems this can be consider as not a bug, but let's make error messages more meaningful.

@MarkPieszak
Copy link
Contributor

You have to really be careful with setTimeouts and setIntervals because one will slow down your server render, while the other will cause it to never render, as it's waiting for all tasks to finish. Make sure you wrap these in inPlatformBrowser calls.

More info here:
https://github.com/angular/universal#universal-gotchas

@SteveSandersonMS
Copy link
Member

Glad you tracked this down. As for the error message, when running in dev environment, normally you will get the exact error message rather than the generic "The connection with the server was terminated abnormally". If you did get the generic message when running in dev mode, do you have repro steps for that? Because it is supposed to give the underlying exception info in that case.

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

No branches or pull requests

3 participants