@kaspernj/api-maker 1.0.194 → 1.0.195

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.194",
19
+ "version": "1.0.195",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -5,11 +5,15 @@ class BaseError extends Error {
5
5
  constructor (message, args = {}) {
6
6
  let messageToUse = message
7
7
 
8
- if (typeof args.response == "object" && dig(args, "response", "errors")) {
9
- if (message) {
10
- messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
11
- } else {
12
- messageToUse = errorMessages(args).join(". ")
8
+ if ("addResponseErrorsToErrorMessage" in args && !args.addResponseErrorsToErrorMessage) {
9
+ messageToUse = message
10
+ } else {
11
+ if (typeof args.response == "object" && dig(args, "response", "errors")) {
12
+ if (message) {
13
+ messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
14
+ } else {
15
+ messageToUse = errorMessages(args).join(". ")
16
+ }
13
17
  }
14
18
  }
15
19
 
@@ -17,8 +21,7 @@ class BaseError extends Error {
17
21
  this.args = args
18
22
 
19
23
  // Maintains proper stack trace for where our error was thrown (only available on V8)
20
- if (Error.captureStackTrace)
21
- Error.captureStackTrace(this, BaseError)
24
+ if (Error.captureStackTrace) Error.captureStackTrace(this, BaseError)
22
25
  }
23
26
 
24
27
  errorMessages () {
@@ -311,7 +311,7 @@ class BaseModel {
311
311
  }
312
312
 
313
313
  static parseValidationErrors ({error, model, options}) {
314
- if (!(error instanceof CustomError)) return
314
+ if (!(error instanceof ValidationError)) return
315
315
  if (!error.args.response.validation_errors) return
316
316
 
317
317
  const validationErrors = new ValidationErrors({
package/src/link.jsx CHANGED
@@ -17,7 +17,7 @@ export default class Link extends React.PureComponent {
17
17
  if (!e.defaultPrevented && !e.ctrlKey && !e.metaKey) {
18
18
  e.preventDefault()
19
19
 
20
- const history = global.apiMakerConfigGlobal?.history
20
+ const history = globalThis.apiMakerConfigGlobal?.history
21
21
 
22
22
  if (!history) throw new Error("History hasn't been set in the API maker configuration")
23
23
 
@@ -1,9 +1,13 @@
1
- const CustomError = require("./custom-error.cjs")
1
+ const BaseError = require("./base-error.cjs")
2
2
  const inflection = require("inflection")
3
3
 
4
- class ValidationError extends CustomError {
4
+ class ValidationError extends BaseError {
5
5
  constructor (validationErrors, args) {
6
- super(validationErrors.getUnhandledErrorMessage() || validationErrors.getErrorMessage(), args)
6
+ const errorMessage = validationErrors.getUnhandledErrorMessage() || validationErrors.getErrorMessage()
7
+ const forwardedArgs = {addResponseErrorsToErrorMessage: false}
8
+ const newArgs = Object.assign({}, args, forwardedArgs)
9
+
10
+ super(errorMessage, newArgs)
7
11
  this.validationErrors = validationErrors
8
12
  }
9
13
 
@@ -96,8 +96,7 @@ class ValidationErrors {
96
96
  return this.validationErrors
97
97
  }
98
98
 
99
- getValidationErrorsForInput (args) {
100
- const {attribute, inputName, onMatchValidationError} = args
99
+ getValidationErrorsForInput ({attribute, inputName, onMatchValidationError}) {
101
100
  const validationErrors = this.validationErrors.filter((validationError) => {
102
101
  if (onMatchValidationError) {
103
102
  return onMatchValidationError(validationError)