DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Krzysztof Platis
Krzysztof Platis

Posted on

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

By default, all http errors from backend endpoints or runtime errors 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), which really interrupt the rendering. Such an error from APP_INITIALIZER 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: https://github.com/Platonn/angular-universal-14-error-handling-default

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

Top comments (0)

πŸ” If you came here from Google, why not take a look at some of our top posts?