@janiscommerce/api
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -9,2 +9,7 @@ # Changelog | ||
## [5.1.0] - 2020-06-23 | ||
### Added | ||
- Added support for error response with messageVariables | ||
- Added new `ErrorWithVariables` to easily send a response with variables | ||
## [5.0.1] - 2020-06-18 | ||
@@ -11,0 +16,0 @@ ### Removed |
@@ -186,3 +186,3 @@ 'use strict'; | ||
this.setResponseError(message, code); | ||
this.setResponseError(message, code, err.messageVariables); | ||
} | ||
@@ -227,7 +227,7 @@ } | ||
this.setResponseError(message, code); | ||
this.setResponseError(message, code, err.messageVariables); | ||
} | ||
} | ||
setResponseError(message, httpCode) { | ||
setResponseError(message, httpCode, messageVariables) { | ||
this.hasError = true; | ||
@@ -239,3 +239,3 @@ | ||
this.api | ||
.setBody({ message }); | ||
.setBody({ message, messageVariables }); | ||
} | ||
@@ -242,0 +242,0 @@ |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const APIError = require('./error'); | ||
const ErrorWithVariables = require('./error-with-variables'); | ||
@@ -11,3 +12,4 @@ module.exports = { | ||
Dispatcher, | ||
APIError | ||
APIError, | ||
ErrorWithVariables | ||
}; |
{ | ||
"name": "@janiscommerce/api", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "A package for managing API from any origin", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -122,2 +122,16 @@ # api | ||
## ErrorWithVariables | ||
This is an error class to use to return easily a message and variables apply to it, for example to handle error translation properly. | ||
Every variable should be a scalar (not an array or object). Otherwise it will be casted to a string. | ||
```js | ||
const { ErrorWithVariables } = require('@janiscommerce/api'); | ||
throw new ErrorWithVariables('some.error.to.translate', { | ||
name: 'Some name to replace in translation' | ||
}) | ||
``` | ||
## Session injection | ||
@@ -124,0 +138,0 @@ *Since 2.0.0* |
26133
10
412
366