Skip to content

Commit 2f8bf61

Browse files
committed
add error message/note display for search errors
1 parent dd06b40 commit 2f8bf61

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

src/components/cveRecordSearchModule.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848
<p id="alertIcon" class="is-hidden">alert</p>
4949
<font-awesome-icon style="flex: 0 0 40px; margin-top:3px" size="lg" icon="exclamation-triangle" role="alert"
5050
aria-labelledby="alertIcon" aria-hidden="false" />
51-
<p class="cve-help-text">
52-
{{ errorMessageStore.errorMessage }}
53-
</p>
51+
<ul class="pl-4" style="list-style: square">
52+
<li v-for="errorMsg in errorMessageStore.errorMessage"
53+
class="cve-help-text" v-html="errorMsg"></li>
54+
</ul>
5455
</div>
5556
</div>
5657
</div>

src/stores/cveListSearch.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineStore } from 'pinia';
2+
import { useErrorMessageStore } from './cveRecord';
23
import { useGenericGlobalsStore } from './genericGlobals';
34
import axios from 'axios';
45

@@ -71,6 +72,10 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
7172
isCveIdPattern() {
7273
return new RegExp(/^CVE-\d{4}-\d{4,7}$/, 'i').test(this.query);
7374
},
75+
resetResults() {
76+
this.searchResults = [];
77+
this.totalSearchResultCount = 0;
78+
},
7479
async search() {
7580
this.isSearching = true;
7681
try{
@@ -168,15 +173,27 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
168173
this.isQueryingSearchService = true;
169174
const searchUrl = `${import.meta.env.VITE_API_BASE_URL}${import.meta.env.VITE_LIST_SEARCH_PATH}`;
170175

176+
this.resetResults();
177+
171178
try {
172179
let payLoad = this.createSearchPayload();
173180
const response = await axios.post(searchUrl, payLoad);
174181

175-
if (response.status === 200) {
182+
const searchMetaData = response.data['search-metadata'];
183+
184+
if (searchMetaData.searchStatus === 'ok') {
176185
this.totalSearchResultCount = response.data.resultsTotal;
177186
this.processSearchResults(response.data.data);
178-
}
187+
} 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+
const ems = useErrorMessageStore();
179193

194+
searchMetaData.errors.forEach(e => ems.pushErrorMessage(e.message));
195+
searchMetaData.notes.forEach(n => ems.pushErrorMessage(n));
196+
}
180197
} catch (e) {
181198
this.isSearchServerError = true;
182199
throw new Error(`getSearchResults >> : ${e}`)

src/stores/cveRecord.ts

+22-11
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,45 @@ export const usecveRecordStore = defineStore('cveRecord', {
7070
});
7171

7272

73-
// The "error message" store handles the error message displayed to the user
73+
// The "error message" store handles the error message(s) displayed to the user
7474
// just below the search input field. A store is used because error messages
7575
// triggered by the user's CVE ID input occur in both the CVERecord module and
76-
// the cveRecordSearch module.
76+
// the cveRecordSearch module. It's also used for messages returned by the
77+
// search in cveListSearch.
78+
79+
type ErrorMessageState = {
80+
errorMessage: string[]
81+
showErrorMessage: boolean
82+
}
7783

7884
export const useErrorMessageStore = defineStore('errorMessage', {
79-
state: () => {
80-
return {
81-
errorMessage: '',
82-
showErrorMessage: false
83-
}
84-
},
85+
state: (): ErrorMessageState => ({
86+
errorMessage: [],
87+
showErrorMessage: false,
88+
}),
8589
getters: {
8690
isErrorMessage: (state) => state.errorMessage.length > 0,
91+
lineCount: (state) => state.errorMessage.length,
8792
},
8893
actions: {
8994
cveIdFormatMessage() {
9095
const formatMessage = 'Required CVE ID format: CVE-YYYY-NNNN';
9196
this.setErrorMessage(formatMessage);
9297
},
98+
pushErrorMessage(message: string) {
99+
if (message.length) {
100+
this.errorMessage.push(message);
101+
this.showErrorMessage = true;
102+
}
103+
},
93104
setErrorMessage(message: string) {
94105
if (message.length) {
95-
this.errorMessage = message;
106+
this.errorMessage = [message];
96107
this.showErrorMessage = true;
97108
} else {
98-
this.errorMessage = '';
109+
this.errorMessage = [];
99110
this.showErrorMessage = false;
100111
}
101-
}
112+
},
102113
}
103114
});

0 commit comments

Comments
 (0)