@kaspernj/api-maker 1.0.173 → 1.0.176

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 CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.173",
19
+ "version": "1.0.176",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -6,7 +6,11 @@ class BaseError extends Error {
6
6
  let messageToUse = message
7
7
 
8
8
  if (typeof args.response == "object" && dig(args, "response", "errors")) {
9
- messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
9
+ if (message) {
10
+ messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
11
+ } else {
12
+ messageToUse = errorMessages(args).join(". ")
13
+ }
10
14
  }
11
15
 
12
16
  super(messageToUse)
@@ -162,7 +162,11 @@ module.exports = class ApiMakerCommandsPool {
162
162
  })
163
163
  error = new ValidationError(validationErrors, {response: commandResponseData})
164
164
  } else {
165
- error = new CustomError(`Command failed`, {response: commandResponseData})
165
+ let errorMessage
166
+
167
+ if (!commandResponseData.errors) { errorMessage = "Command failed" }
168
+
169
+ error = new CustomError(errorMessage, {response: commandResponseData})
166
170
  }
167
171
 
168
172
  commandData.reject(error)
package/src/config.js CHANGED
@@ -12,7 +12,11 @@ class ApiMakerConfig {
12
12
  }
13
13
 
14
14
  getHost() {
15
- return this.global.host
15
+ const host = this.global.host
16
+
17
+ if (typeof host == "function") return host()
18
+
19
+ return host
16
20
  }
17
21
 
18
22
  getRouteDefinitions() {
package/src/link.jsx CHANGED
@@ -5,17 +5,23 @@ export default class Link extends React.PureComponent {
5
5
  const {to, onClick, ...restProps} = this.props
6
6
 
7
7
  return (
8
- <a href={to} {...restProps} onClick={onClick || this.onLinkClicked} />
8
+ <a href={to} {...restProps} onClick={this.onLinkClicked} />
9
9
  )
10
10
  }
11
11
 
12
- onLinkClicked = (e) => {
13
- e.preventDefault()
12
+ onLinkClicked = (e, ...restArgs) => {
13
+ const {onClick} = this.props
14
14
 
15
- const history = global.apiMakerConfigGlobal?.history
15
+ if (onClick) onClick(e, ...restArgs)
16
16
 
17
- if (!history) throw new Error("History hasn't been set in the API maker configuration")
17
+ if (!e.defaultPrevented) {
18
+ e.preventDefault()
18
19
 
19
- history.push(this.props.to)
20
+ const history = global.apiMakerConfigGlobal?.history
21
+
22
+ if (!history) throw new Error("History hasn't been set in the API maker configuration")
23
+
24
+ history.push(this.props.to)
25
+ }
20
26
  }
21
27
  }