Skip to content

Commit 0b9a7ed

Browse files
committed
feat: Add error state to the make-find-mixin
1 parent d6f1fb6 commit 0b9a7ed

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/make-find-mixin.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default function makeFindMixin(options) {
5757
const FETCH_PARAMS = `${prefix}FetchParams`
5858
const WATCH = `${prefix}Watch`
5959
const QUERY_WHEN = `${prefix}QueryWhen`
60+
const ERROR = `${prefix}Error`
6061
const FIND_ACTION = `find${capitalized}`
6162
const FIND_GETTER = `find${capitalized}InStore`
6263
const HAVE_ITEMS_BEEN_REQUESTED_ONCE = `have${capitalized}BeenRequestedOnce`
@@ -71,7 +72,8 @@ export default function makeFindMixin(options) {
7172
[HAVE_ITEMS_LOADED_ONCE]: false,
7273
[WATCH]: watch,
7374
[QID]: qid,
74-
[MOST_RECENT_QUERY]: null
75+
[MOST_RECENT_QUERY]: null,
76+
[ERROR]: null
7577
}
7678
// Should only be used with actual fetching API calls.
7779
const getParams = ({ providedParams, params, fetchParams }) => {
@@ -181,6 +183,9 @@ export default function makeFindMixin(options) {
181183
return this.$store
182184
.dispatch(`${serviceName}/find`, paramsToUse)
183185
.then(response => {
186+
// To prevent thrashing, only clear ERROR on response, not on initial request.
187+
this[ERROR] = null
188+
184189
this[HAVE_ITEMS_LOADED_ONCE] = true
185190
const queryInfo = getQueryInfo(paramsToUse, response)
186191
// @ts-ignore
@@ -192,6 +197,10 @@ export default function makeFindMixin(options) {
192197
this[IS_FIND_PENDING] = false
193198
return response
194199
})
200+
.catch(error => {
201+
this[ERROR] = error
202+
return error
203+
})
195204
}
196205
} else {
197206
if (this[MOST_RECENT_QUERY]) {

0 commit comments

Comments
 (0)