-
Notifications
You must be signed in to change notification settings - Fork 381
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
feat: CXSPA-2066 SSR Error Handling #18742
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previous behavior: When `/products` endpoint returned a http error, the code broke in [this line](https://github.com/SAP/spartacus/blob/ed1e1a78c488b1e1214491ffa736612287f8cf70/projects/core/src/product/store/effects/product.effect.ts#L77), complaining that `this` is undefined. Fix: Preserve the context of `this` which was lost in [this line](https://github.com/SAP/spartacus/blob/ed1e1a78c488b1e1214491ffa736612287f8cf70/projects/core/src/product/store/effects/product.effect.ts#L52) The problem was revealed only after we implemented [CXSPA-2251](https://jira.tools.sap/browse/CXSPA-2251) where we referenced `this` by adding `this.logger` to the method `ProductEffects.productLoadEffect` fixes https://jira.tools.sap/browse/CXSPA-3902
Co-authored-by: Krzysztof Platis <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Krzysztof Platis <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
# Conflicts: # projects/core/src/product/store/actions/product-references.action.ts # projects/core/src/product/store/actions/product-reviews.action.ts # projects/core/src/product/store/effects/product-reviews.effect.ts # projects/core/src/state/utils/entity-loader/entity-loader.action.ts
This pull request introduces methodologies for integrating multiple error interceptors that manage errors within the Server-Side Rendering (SSR) framework. This architectural augmentation preserves backward compatibility, mitigating any potential disruptions for end-users upon the incorporation of new error interceptors into the system. With the introduction of this enhancement, it becomes easier for users to include new error interceptors, giving them the flexibility to determine the order in which these interceptors are applied within the system. This priority setting allows users to control how these interceptors operate and influence the workflow of the system. The order is: High priority Normal or no priority Low priority Preserves the original order within a group of interceptors with the same priority.
…I_ERROR_HANDLERS to singular form (#18776)
…t ExpressJS handlers (#18753)
Merge Checks Failed
|
Merge Checks Failed
|
Merge Checks Failed
|
Merge Checks Failed
|
Merge Checks Failed
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains one of the missing puzzles required to enjoy SSR provided by Spartacus - Error Handling.
In the current shape of Angular SSR, that Spartacus uses under the hood, if any async error occurs during rendering, the page renders without any information on whether the error occurred and an app returns the effect of rendering, potentially malformed, due to e.g. runtime error in the app logic, or due to the HTTP error when calling API, with the wrong, misleading status of 200. As a consequence, pages that encountered errors while rendering and are possibly missing some data are indexed by Google.
The same issue occurs, when customer enters the unknown URL - Spartacus returns an error page, but with misleading status 200. Because of that, unknown URLs are indexed by Google.
Both scenarios may drastically affect the SEO of the page.
To solve the issues mentioned above, Spartacus introduces SSR Error Handling to properly react to errors that occur during the rendering page on the server and to inform the user (and Google crawlers) about the encountered issue and its type.
The whole feature is controlled by three feature flags:
propagateErrorsToServer
feature toggle to propagate to the ExpressJS the async error captured during the rendering,ssrStrictErrorHandlingForHttpAndNgrx
feature toggle to capture async HTTP errors as well as runtime errors in NgRx flow,ssrFeatureToggle.avoidCachingErrors
inSsrOptimizationOptions
to not cache error pagesArchitectural details:
HttpErrorHandlerinterceptor
responsible for capturing HTTP errors and forwarding wrapped errors based on their cause:CmsPageNotFoundOutboundHttpError
if 404 HTTP error occurred when callingcms/pages
OnboundHttpError
if any other HTTP error occurred (i.e. non-404 in cms/pages OR any http error in any other API call)CxErrorHandlerEffect
that captures NgRx actions of typeErrorAction
and forwards error from their payload to the error handler.LoggingErrorHandler
usingLoggingService
under the hood to log captured errorsPropagatingToServerErrorHandler
that propagates error capturied during SSR toCxCommonEngine
CxCommonEngine
- wrapper for Angular'sCommonEngine
that handles propagated errors during SSRdefaultEspressErrorHandlers
middleware for ExpressJS that handles captured errors and falls back to CSR with the proper response statusRenderingCache
that help to avoid caching renders when an error occurs:ssrFeatureToggles.avoidCachingErrors
(boolean, feature toggle which will be eventually removed due to breaking changes policy) orshouldCacheRenderingResult
(function)OptimizedSsrEngine
to inform that rendering results with error (for better traceability)Apart from a new functionality for customers, this PR introduces:
no-ngrx-fail-action-without-error-action-implementation
which makes sure that NgRx failure actions implement the ErrorAction interface necessary for an error in the NgRx flow to be caughtcloses CXSPA-2066