DEV Community

Krzysztof Platis
Krzysztof Platis

Posted on • Updated on

Your SEO in danger - Angular Universal ignores errors in your app 🚨

By default, all http errors from backend endpoints or runtime errors happening asynchronously in your SSR app are ignored by the Angular Universal Express engine. ExpressJS always returns to a client a "success" response (with a http status 200) with whatever HTML got eventually rendered, regardless any runtime errors.
Obviously http errors from backend endpoints may result in missing the crucial data to be displayed in final HTML output. Or a runtime error in a component’s logic might cause rendering incorrectly a part of the page. Because Angular Universal Express ignores such errors, the malformed HTML result sent to the client may be eventually indexed by Google, harming your SEO.

The only exception are unsuccessful APP_INITIALIZER hooks (returning a rejected Promise or errored RxJs stream) and errors in a synchronous bootstrap of the root component - which really interrupt the rendering. Such an error from APP_INITIALIZER (or from constructor of the root component) is thrown up to the ExpressJS server. This by default causes sending to a client a raw error’s stacktrace along with the http status 500.

For more, see a minimal reproduction repo:

Disclaimer: this article refers to Angular in version 14.2. The next versions may differ in behavior.

EDIT: I've created a feature request in the Angular repo for propagating asynchronous errors in SSR: https://github.com/angular/angular/issues/50829

Latest comments (0)