@kaspernj/api-maker 1.0.160 → 1.0.163
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/base-error.cjs +33 -0
- package/src/commands-pool.cjs +5 -2
- package/src/custom-error.cjs +2 -39
- package/src/destroy-error.cjs +7 -0
- package/src/error-messages.cjs +14 -0
- package/src/validation-error.cjs +1 -1
- package/src/with-router.jsx +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const {dig, digg} = require("diggerize")
|
|
2
|
+
const errorMessages = require("./error-messages.cjs")
|
|
3
|
+
|
|
4
|
+
class BaseError extends Error {
|
|
5
|
+
constructor (message, args = {}) {
|
|
6
|
+
let messageToUse = message
|
|
7
|
+
|
|
8
|
+
if (typeof args.response == "object" && dig(args, "response", "errors")) {
|
|
9
|
+
messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
super(messageToUse)
|
|
13
|
+
this.args = args
|
|
14
|
+
|
|
15
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
16
|
+
if (Error.captureStackTrace)
|
|
17
|
+
Error.captureStackTrace(this, BaseError)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
errorMessages () {
|
|
21
|
+
return errorMessages(this.args)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
errorTypes () {
|
|
25
|
+
if (typeof this.args.response == "object") {
|
|
26
|
+
return digg(this, "args", "response", "errors").map((error) => digg(error, "type"))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
BaseError.apiMakerType = "BaseError"
|
|
32
|
+
|
|
33
|
+
module.exports = BaseError
|
package/src/commands-pool.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const Api = require("./api.cjs")
|
|
2
2
|
const CommandSubmitData = require("./command-submit-data.cjs")
|
|
3
3
|
const CustomError = require("./custom-error.cjs")
|
|
4
|
+
const DestroyError = require("./destroy-error.cjs")
|
|
4
5
|
const Deserializer = require("./deserializer.cjs")
|
|
5
6
|
const {dig, digg} = require("diggerize")
|
|
6
7
|
const FormDataObjectizer = require("form-data-objectizer")
|
|
@@ -152,14 +153,16 @@ module.exports = class ApiMakerCommandsPool {
|
|
|
152
153
|
handleFailedResponse (commandData, commandResponseData) {
|
|
153
154
|
let error
|
|
154
155
|
|
|
155
|
-
if (commandResponseData.error_type == "
|
|
156
|
+
if (commandResponseData.error_type == "destroy_error") {
|
|
157
|
+
error = new DestroyError(`Destroy failed`, {response: commandResponseData})
|
|
158
|
+
} else if (commandResponseData.error_type == "validation_error") {
|
|
156
159
|
const validationErrors = new ValidationErrors({
|
|
157
160
|
model: digg(commandResponseData, "model"),
|
|
158
161
|
validationErrors: digg(commandResponseData, "validation_errors")
|
|
159
162
|
})
|
|
160
163
|
error = new ValidationError(validationErrors, {response: commandResponseData})
|
|
161
164
|
} else {
|
|
162
|
-
error = new CustomError(
|
|
165
|
+
error = new CustomError(`Command failed`, {response: commandResponseData})
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
commandData.reject(error)
|
package/src/custom-error.cjs
CHANGED
|
@@ -1,43 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const BaseError = require("./base-error.cjs")
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
if (typeof args.response == "object") {
|
|
5
|
-
return digg(args, "response", "errors").map((error) => {
|
|
6
|
-
if (typeof error == "string") {
|
|
7
|
-
return error
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return digg(error, "message")
|
|
11
|
-
})
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
class CustomError extends Error {
|
|
16
|
-
constructor (message, args = {}) {
|
|
17
|
-
let messageToUse = message
|
|
18
|
-
|
|
19
|
-
if (typeof args.response == "object" && dig(args, "response", "errors")) {
|
|
20
|
-
messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
super(messageToUse)
|
|
24
|
-
this.args = args
|
|
25
|
-
|
|
26
|
-
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
27
|
-
if (Error.captureStackTrace)
|
|
28
|
-
Error.captureStackTrace(this, CustomError)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
errorMessages () {
|
|
32
|
-
return errorMessages(this.args)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
errorTypes () {
|
|
36
|
-
if (typeof this.args.response == "object") {
|
|
37
|
-
return digg(this, "args", "response", "errors").map((error) => digg(error, "type"))
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
3
|
+
class CustomError extends BaseError {}
|
|
41
4
|
|
|
42
5
|
CustomError.apiMakerType = "CustomError"
|
|
43
6
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const {digg} = require("diggerize")
|
|
2
|
+
const errorMessages = (args) => {
|
|
3
|
+
if (typeof args.response == "object") {
|
|
4
|
+
return digg(args, "response", "errors").map((error) => {
|
|
5
|
+
if (typeof error == "string") {
|
|
6
|
+
return error
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return digg(error, "message")
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = errorMessages
|
package/src/validation-error.cjs
CHANGED
package/src/with-router.jsx
CHANGED
|
@@ -118,7 +118,7 @@ export default (WrapperComponent) => class WithRouter extends React.Component {
|
|
|
118
118
|
const matchingRoute = this.findMatchingRoute()
|
|
119
119
|
const match = {
|
|
120
120
|
matchingRoute,
|
|
121
|
-
params: matchingRoute
|
|
121
|
+
params: matchingRoute?.params
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
return (
|