Skip to content

Commit 46c184f

Browse files
committed
cveListSearch: fix getIdData(), handle missing data in getSearchResults()
1 parent 77f6dab commit 46c184f

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

src/stores/cveListSearch.js

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
9797
// if record is not found, find potential reserved/rejected ID
9898
if (this.isCveIdPattern() && Object.keys(this.recordData).length === 0) {
9999
await this.getIdData();
100-
}
101-
102-
throw new Error('search() >> error with getSearchResults(), getRecordData(), or getIdData()');
100+
} else
101+
throw new Error(`search() >> error with getSearchResults(), getRecordData(): ${error}`);
103102
} finally {
104103
this.isSearching = false;
105104
this.setUpInitialPagination();
@@ -123,7 +122,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
123122
cna: cveRecordData?.containers?.cna?.providerMetadata?.shortName || 'No CNA provided',
124123
cnaOrgId: cveRecordData?.containers?.cna?.providerMetadata?.orgId || '',
125124
descriptions: descriptions,
126-
relevancyScore: 'not appliciable'
125+
relevancyScore: 'not applicable'
127126
}
128127
this.recordData = recordDataSummary;
129128

@@ -151,15 +150,15 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
151150
const getIdUrl = `${useGenericGlobalsStore().currentServicesUrl}/api/cve-id/${this.cveId}`;
152151
try {
153152
const response = await axios.get(getIdUrl);
154-
const idData = response || {};
153+
const idData = response.data ?? {};
155154
this.isIdOrRecordFound = true;
156155
this.isAnId = true;
157-
if (idData.status === 200 && idData?.data?.error === undefined) {
158-
this.idData = idData.data;
156+
if (response.status === 200 && response.data?.error === undefined) {
157+
this.idData = idData;
159158
if (idData.state === 'RESERVED') {
160159
this.isReserved = true;
161160
this.isArecord = false;
162-
} else if (this.$store.state.idData.state === 'REJECTED') {
161+
} else if (idData.state === 'REJECTED') {
163162
this.isRejected = true;
164163
this.isArecord = false;
165164
}
@@ -176,32 +175,45 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
176175
this.resetResults();
177176

178177
try {
178+
const ems = useErrorMessageStore();
179179
let payLoad = this.createSearchPayload();
180180
const response = await axios.post(searchUrl, payLoad);
181181

182-
const searchMetaData = response.data.searchMetadata;
182+
if (!response.data) {
183+
184+
// This shouldn't happen, but it has so it's possible. This is
185+
// different from a successful search with no results - the service
186+
// returned nothing in the 'data' field. Rather than ignore it,
187+
// indicate with a message that nothing was returned. The problem may
188+
// be that the service can't handle something in the input string.
189+
190+
ems.pushErrorMessage('No response data from search - check input');
183191

184-
if (searchMetaData.searchStatus === 'ok') {
185-
this.totalSearchResultCount = response.data.resultsTotal;
186-
this.processSearchResults(response.data.data);
187192
} else {
188-
// There's likely something invalid in the search string.
189-
// Error message(s) and note(s) returned in the response will be
190-
// displayed to the user.
191-
//
192-
// We could reset the error message store here, because this is a
193-
// "new" search, but resetting may also mask an issue where the
194-
// search is inadvertently done multiple times (resulting in
195-
// duplicate error messages displayed).
196-
197-
const ems = useErrorMessageStore();
198-
199-
searchMetaData.errors.forEach(e => ems.pushErrorMessage(e.message));
200-
searchMetaData.notes.forEach(n => ems.pushErrorMessage(n));
193+
194+
const searchMetaData = response.data.searchMetadata;
195+
196+
if (searchMetaData.searchStatus === 'ok') {
197+
this.totalSearchResultCount = response.data.resultsTotal;
198+
this.processSearchResults(response.data.data);
199+
} else {
200+
// There's likely something invalid in the search string.
201+
// Error message(s) and note(s) returned in the response will be
202+
// displayed to the user.
203+
//
204+
// We could reset the error message store here, because this is a
205+
// "new" search, but resetting may also mask an issue where the
206+
// search is inadvertently done multiple times (resulting in
207+
// duplicate error messages displayed).
208+
209+
searchMetaData.errors.forEach(e => ems.pushErrorMessage(e.message));
210+
searchMetaData.notes.forEach(n => ems.pushErrorMessage(n));
211+
}
201212
}
202213
} catch (e) {
203214
this.isSearchServerError = true;
204-
throw new Error(`getSearchResults >> : ${e}`)
215+
if (e.code !== 'ERR_NETWORK')
216+
throw new Error(`getSearchResults >> : ${e}`);
205217
} finally {
206218
this.isQueryingSearchService = false;
207219
this.decrement('totalExecutingRequests');
@@ -210,7 +222,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
210222
processSearchResults(results){
211223
const parsedResults = [];
212224

213-
if (results.length >> 0) {
225+
if (results.length > 0) {
214226
results.forEach((result) => {
215227
parsedResults.push({
216228
cveId: result._id,
@@ -228,13 +240,17 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
228240
let descriptions = [];
229241
if (recordData.cveMetadata?.state === "PUBLISHED") {
230242
recordData.containers?.cna?.descriptions.forEach((description) => {
231-
if (this.isEnglishLanguage(description.lang)) descriptions.push(this.processShowMoreShowLessDescription(description.value));
243+
if (this.isEnglishLanguage(description.lang))
244+
descriptions.push(this.processShowMoreShowLessDescription(description.value));
232245
});
233246
} else if (recordData.cveMetadata?.state === "REJECTED") {
234247
recordData.containers?.cna?.rejectedReasons.forEach((rejectedReason) => {
235-
if (this.isEnglishLanguage(rejectedReason.lang)) descriptions.push(this.processShowMoreShowLessDescription(rejectedReason.value));
248+
if (this.isEnglishLanguage(rejectedReason.lang))
249+
descriptions.push(this.processShowMoreShowLessDescription(rejectedReason.value));
236250
});
237-
} else { // resevered/rejected ID w/o a CVE record does not have description, and that logic is handled in corresponding Vue file
251+
} else {
252+
// reserved/rejected ID w/o a CVE record does not have description, and
253+
// that logic is handled in corresponding Vue file
238254
descriptions.push('No description provided');
239255
}
240256

0 commit comments

Comments
 (0)