frappe-ui 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/resources.js +27 -5
package/package.json
CHANGED
package/src/utils/resources.js
CHANGED
|
@@ -47,6 +47,24 @@ function createResource(options, vm, getResource) {
|
|
|
47
47
|
}
|
|
48
48
|
out.params = params || options.params
|
|
49
49
|
out.loading = true
|
|
50
|
+
|
|
51
|
+
if (options.validate) {
|
|
52
|
+
let invalidMessage
|
|
53
|
+
try {
|
|
54
|
+
invalidMessage = await options.validate.call(vm, out.params)
|
|
55
|
+
if (invalidMessage && typeof invalidMessage == 'string') {
|
|
56
|
+
let error = new Error(invalidMessage)
|
|
57
|
+
handleError(error)
|
|
58
|
+
out.loading = false
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
handleError(error)
|
|
63
|
+
out.loading = false
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
50
68
|
try {
|
|
51
69
|
let data = await resourceFetcher(options.method, params || options.params)
|
|
52
70
|
out.previousData = out.data || null
|
|
@@ -56,11 +74,7 @@ function createResource(options, vm, getResource) {
|
|
|
56
74
|
options.onSuccess.call(vm, data)
|
|
57
75
|
}
|
|
58
76
|
} catch (error) {
|
|
59
|
-
|
|
60
|
-
out.error = error
|
|
61
|
-
if (options.onError) {
|
|
62
|
-
options.onError.call(vm, error)
|
|
63
|
-
}
|
|
77
|
+
handleError(error)
|
|
64
78
|
}
|
|
65
79
|
out.loading = false
|
|
66
80
|
}
|
|
@@ -77,6 +91,14 @@ function createResource(options, vm, getResource) {
|
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
93
|
|
|
94
|
+
function handleError(error) {
|
|
95
|
+
console.error(error)
|
|
96
|
+
out.error = error
|
|
97
|
+
if (options.onError) {
|
|
98
|
+
options.onError.call(vm, error)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
80
102
|
if (cacheKey && !cached[cacheKey]) {
|
|
81
103
|
cached[cacheKey] = out
|
|
82
104
|
}
|