@@ -40,6 +40,8 @@ import {
40
40
} from "@webiny/api-elasticsearch/types" ;
41
41
import { CmsEntryStorageOperations , CmsIndexEntry } from "~/types" ;
42
42
import { createElasticsearchBody } from "./elasticsearch/body" ;
43
+ import { logIgnoredEsResponseError } from "./elasticsearch/logIgnoredEsResponseError" ;
44
+ import { shouldIgnoreEsResponseError } from "./elasticsearch/shouldIgnoreEsResponseError" ;
43
45
import { createLatestRecordType , createPublishedRecordType , createRecordType } from "./recordType" ;
44
46
import { StorageOperationsCmsModelPlugin } from "@webiny/api-headless-cms" ;
45
47
import { WriteRequest } from "@webiny/aws-sdk/client-dynamodb" ;
@@ -63,24 +65,6 @@ export interface CreateEntriesStorageOperationsParams {
63
65
plugins : PluginsContainer ;
64
66
}
65
67
66
- const IGNORED_ES_SEARCH_EXCEPTIONS = [
67
- "index_not_found_exception" ,
68
- "search_phase_execution_exception"
69
- ] ;
70
-
71
- const shouldIgnoreElasticsearchException = ( ex : WebinyError ) => {
72
- if ( IGNORED_ES_SEARCH_EXCEPTIONS . includes ( ex . message ) ) {
73
- console . log ( `Ignoring Elasticsearch exception: ${ ex . message } ` ) ;
74
- console . log ( {
75
- code : ex . code ,
76
- data : ex . data ,
77
- stack : ex . stack
78
- } ) ;
79
- return true ;
80
- }
81
- return false ;
82
- } ;
83
-
84
68
export const createEntriesStorageOperations = (
85
69
params : CreateEntriesStorageOperationsParams
86
70
) : CmsEntryStorageOperations => {
@@ -303,10 +287,6 @@ export const createEntriesStorageOperations = (
303
287
} )
304
288
] ;
305
289
306
- const { index } = configurations . es ( {
307
- model
308
- } ) ;
309
-
310
290
if ( isPublished ) {
311
291
items . push (
312
292
entity . putBatch ( {
@@ -1096,21 +1076,28 @@ export const createEntriesStorageOperations = (
1096
1076
index,
1097
1077
body
1098
1078
} ) ;
1099
- } catch ( ex ) {
1079
+ } catch ( error ) {
1100
1080
/**
1101
1081
* We will silently ignore the `index_not_found_exception` error and return an empty result set.
1102
1082
* This is because the index might not exist yet, and we don't want to throw an error.
1103
1083
*/
1104
- if ( shouldIgnoreElasticsearchException ( ex ) ) {
1084
+ if ( shouldIgnoreEsResponseError ( error ) ) {
1085
+ logIgnoredEsResponseError ( {
1086
+ error,
1087
+ model,
1088
+ indexName : index
1089
+ } ) ;
1090
+
1105
1091
return {
1106
1092
hasMoreItems : false ,
1107
1093
totalCount : 0 ,
1108
1094
cursor : null ,
1109
1095
items : [ ]
1110
1096
} ;
1111
1097
}
1112
- throw new WebinyError ( ex . message , ex . code || "ELASTICSEARCH_ERROR" , {
1113
- error : ex ,
1098
+
1099
+ throw new WebinyError ( error . message , error . code || "ELASTICSEARCH_ERROR" , {
1100
+ error,
1114
1101
index,
1115
1102
body,
1116
1103
model
@@ -1807,15 +1794,21 @@ export const createEntriesStorageOperations = (
1807
1794
index,
1808
1795
body
1809
1796
} ) ;
1810
- } catch ( ex ) {
1811
- if ( shouldIgnoreElasticsearchException ( ex ) ) {
1797
+ } catch ( error ) {
1798
+ if ( shouldIgnoreEsResponseError ( error ) ) {
1799
+ logIgnoredEsResponseError ( {
1800
+ error,
1801
+ model,
1802
+ indexName : index
1803
+ } ) ;
1812
1804
return [ ] ;
1813
1805
}
1806
+
1814
1807
throw new WebinyError (
1815
- ex . message || "Error in the Elasticsearch query." ,
1816
- ex . code || "ELASTICSEARCH_ERROR" ,
1808
+ error . message || "Error in the Elasticsearch query." ,
1809
+ error . code || "ELASTICSEARCH_ERROR" ,
1817
1810
{
1818
- error : ex ,
1811
+ error,
1819
1812
index,
1820
1813
model,
1821
1814
body
0 commit comments