File tree 3 files changed +31
-6
lines changed
assets/src/translations/en
core/src/product/store/effects
3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 90
90
"exactMatch" : " {{ term }}" ,
91
91
"empty" : " Ask us anything"
92
92
},
93
- "closeSearchPanel" : " Close"
93
+ "closeSearchPanel" : " Close" ,
94
+ "queryError" : " Your search query is incorrectly formatted. Please remove special characters like \" :\" and try again."
94
95
},
95
96
"sorting" : {
96
97
"date" : " Date" ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { SearchConfig } from '../../model/search-config';
12
12
import { ProductActions } from '../actions/index' ;
13
13
import * as fromEffects from './product-search.effect' ;
14
14
import createSpy = jasmine . createSpy ;
15
+ import { GlobalMessageService } from '@spartacus/core' ;
15
16
16
17
const searchResult : ProductSearchPage = { products : [ ] } ;
17
18
const suggestionList : Occ . SuggestionList = { suggestions : [ ] } ;
@@ -21,6 +22,9 @@ class MockProductSearchConnector {
21
22
getSuggestions = createSpy ( ) . and . returnValue ( of ( suggestionList . suggestions ) ) ;
22
23
}
23
24
25
+ class MockGlobalMessageService implements Partial < GlobalMessageService > {
26
+ add = createSpy ( ) ;
27
+ }
24
28
describe ( 'ProductSearch Effects' , ( ) => {
25
29
let actions$ : Observable < Action > ;
26
30
let effects : fromEffects . ProductsSearchEffects ;
@@ -29,6 +33,7 @@ describe('ProductSearch Effects', () => {
29
33
beforeEach ( ( ) => {
30
34
TestBed . configureTestingModule ( {
31
35
providers : [
36
+ { provide : GlobalMessageService , useClass : MockGlobalMessageService } ,
32
37
{
33
38
provide : ProductSearchConnector ,
34
39
useClass : MockProductSearchConnector ,
Original file line number Diff line number Diff line change @@ -12,10 +12,16 @@ import { LoggerService } from '../../../logger';
12
12
import { tryNormalizeHttpError } from '../../../util/try-normalize-http-error' ;
13
13
import { ProductSearchConnector } from '../../connectors/search/product-search.connector' ;
14
14
import { ProductActions } from '../actions/index' ;
15
+ import { HttpErrorModel } from '../../../model' ;
16
+ import {
17
+ GlobalMessageService ,
18
+ GlobalMessageType ,
19
+ } from '../../../global-message' ;
15
20
16
21
@Injectable ( )
17
22
export class ProductsSearchEffects {
18
23
protected logger = inject ( LoggerService ) ;
24
+ protected globalMessageService = inject ( GlobalMessageService ) ;
19
25
20
26
searchProducts$ : Observable <
21
27
ProductActions . SearchProductsSuccess | ProductActions . SearchProductsFail
@@ -35,14 +41,27 @@ export class ProductsSearchEffects {
35
41
action . auxiliary
36
42
) ;
37
43
} ) ,
38
- catchError ( ( error ) =>
39
- of (
44
+ catchError ( ( error ) => {
45
+ const normalizedError : HttpErrorModel = tryNormalizeHttpError (
46
+ error ,
47
+ this . logger
48
+ ) ;
49
+ if (
50
+ normalizedError ?. details ?. [ 0 ] . type ===
51
+ 'ArrayIndexOutOfBoundsError'
52
+ ) {
53
+ this . globalMessageService . add (
54
+ { key : 'searchBox.queryError' } ,
55
+ GlobalMessageType . MSG_TYPE_ERROR
56
+ ) ;
57
+ }
58
+ return of (
40
59
new ProductActions . SearchProductsFail (
41
- tryNormalizeHttpError ( error , this . logger ) ,
60
+ normalizedError ,
42
61
action . auxiliary
43
62
)
44
- )
45
- )
63
+ ) ;
64
+ } )
46
65
) ;
47
66
} )
48
67
)
You can’t perform that action at this time.
0 commit comments