-
Notifications
You must be signed in to change notification settings - Fork 87
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: map errors into an object #1108
feat: map errors into an object #1108
Conversation
d3dbd18
to
68a3bd8
Compare
I discussed the error behavior with @SGrueber. We would continue to display error messages for a single product in the mini shopping cart. We would leave the behavior for this case as it is. @ivopereira15 @dhhyi Is this behavior fine for you guys? |
Yes, I will |
20fc4a9
to
795c913
Compare
Hi @ivopereira15, can you let me know why you used the |
Hi all. @MaxKless The error substate its working only when you have a bad request. Like a Status Code: 422 Unprocessable Entity. This is a clear error message that will be handled by Lets imagine in the quickorder (that was one the problems that we found) we are trying to add to cart two products. One that we will have an error and other will be success. The response is Status Code: 207 Multi-Status. here what we receive from the request. What i did was put that error inside the infos object. Since we already were showing alert/info error using the info object, could be a good idea to show the error too. |
|
||
export interface BasketInfo { | ||
causes?: BasketFeedback[]; | ||
code: string; | ||
message: string; | ||
error?: ErrorFeedback[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is an array, it should be called errors
imo.
@@ -10,4 +23,6 @@ export interface HttpError { | |||
|
|||
/** human readable (and localized) error message */ | |||
message?: string; | |||
|
|||
causes?: ErrorFeedback[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a documented property like the others.
I also think it would be good to rename the property - see comment on mini-basket-content.component.html
*/ | ||
@Component({ | ||
selector: 'ish-shopping-basket-error-message', | ||
template: '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a component without a template isn't very nice. Something is created in the DOM but only used for state management, kind of like an effect.
Since I understand that this logic is component-specific and doesn't belong in an effect, I would extract the logic to the parent component (shopping-basket.component) and subscribing there or using rx state's hold
method to to trigger a component state side-effect like the context facades do it.
if (infoError) { | ||
infoError?.map(error => { | ||
this.messageFacade.error({ | ||
message: `<b>${error.message}</b> - ${error.causes?.[0].message} ${error.causes?.[0].parameters?.sku}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide some insight as to why only the first error is dispatched here?
<ng-container *ngIf="error.causes as productCauses"> | ||
<div *ngFor="let productCause of productCauses" class="text-danger"> | ||
<strong>{{ productCause.message }}</strong> | ||
<ng-container *ngIf="productCause.causes as causes"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the naming could be improved here. The fact that theres two nested
causesproperties in the model really makes this code incredibly hard to read and confusing. Since the top-level
causesproperty is of type
ErrorFeedback`, maybe the naming could be similar to that?
What do you think?
when(checkoutFacade.basketInfoError$).thenReturn(of(undefined)); | ||
}); | ||
|
||
it('should be created', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the behavior currently defined in the component is pretty straightforward to test and we should probably do so wherever it ends up.
@@ -85,6 +85,7 @@ export class CheckoutFacade { | |||
basketChange$ = this.basketChangeInternal$.asObservable(); | |||
basketError$ = this.store.pipe(select(getBasketError)); | |||
basketInfo$ = this.store.pipe(select(getBasketInfo)); | |||
basketInfoError$ = this.basketInfo$.pipe(map(info => (info?.length ? info[0].error : undefined))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be its own selector?
Also, maybe this is the wrong place to ask this so please let me know if that's the case but can you explain the store structure here a bit? @SGrueber
How come there's both a basket.info
as well as a info
substate in the basket state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basket.info contains info of the get basket (or the result of any call that returns the whole basket ). The info sub state contains the info of the last basket operation, e.g. addProductToCart. Because after each basket operation a get basket is triggered we need both info values.
This reverts commit 46ff1dc.
067ef0c
to
d867ffa
Compare
Co-authored-by: Silke Grueber <s.grueber@intershop.de>
Co-authored-by: Silke Grueber <s.grueber@intershop.de>
has been merged by #1230 |
PR Type
[ X] Bugfix
[ X] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no API changes)
[ ] Build-related changes
[ ] CI-related changes
[ ] Documentation content changes
[ ] Application / infrastructure changes
[ ] Other:
What Is the Current Behavior?
At this moment when we have more than one error we are showing an warning on browser console. This is a problem in the quick order because when we have more than one product with error/errors we dont show feedback to the customer.
Also when we are showing the error we dont know which product we are having the error.
What Is the New Behavior?
With this change we are fixing two problems
We are adding a property named
causes
to the HttpError. This property will have the error message with more details and if it has will have the product sku.Examples

Quick order when we are trying to add two products
Does this PR Introduce a Breaking Change?
[ ] Yes
[ X] No
Other Information