Skip to content

Commit ebccc6b

Browse files
committed
feat: add error state to make-get-mixin
1 parent 0b9a7ed commit ebccc6b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/make-get-mixin.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default function makeFindMixin(options) {
5252
const FETCH_PARAMS = `${prefix}FetchParams`
5353
const WATCH = `${prefix}Watch`
5454
const QUERY_WHEN = `${prefix}QueryWhen`
55+
const ERROR = `${prefix}Error`
5556
const GET_ACTION = `get${capitalized}`
5657
const GET_GETTER = `get${capitalized}FromStore`
5758
const LOCAL = `${prefix}Local`
@@ -60,7 +61,8 @@ export default function makeFindMixin(options) {
6061
const data = {
6162
[IS_GET_PENDING]: false,
6263
[WATCH]: watch,
63-
[QID]: qid
64+
[QID]: qid,
65+
[ERROR]: null
6466
}
6567

6668
const mixin = {
@@ -97,9 +99,16 @@ export default function makeFindMixin(options) {
9799
return this.$store
98100
.dispatch(`${this[SERVICE_NAME]}/get`, [idToUse, paramsToUse])
99101
.then(response => {
102+
// To prevent thrashing, only clear ERROR on response, not on initial request.
103+
this[ERROR] = null
104+
100105
this[IS_GET_PENDING] = false
101106
return response
102107
})
108+
.catch(error => {
109+
this[ERROR] = error
110+
return error
111+
})
103112
}
104113
}
105114
}

0 commit comments

Comments
 (0)