From 4d6733b9271a11e947e9c43051759afc71794a9e Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 7 Apr 2021 18:14:18 +1200 Subject: [PATCH] Improved docs around {{max}} & {{count}} refs https://github.com/TryGhost/Team/issues/587 - Improved description and provided example use of error message template variables that are available for "MaxLimit" types of limits --- ghost/limit-service/README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ghost/limit-service/README.md b/ghost/limit-service/README.md index 0f3ba90f8f..6e4c5fad2e 100644 --- a/ghost/limit-service/README.md +++ b/ghost/limit-service/README.md @@ -95,7 +95,7 @@ if (limitService.isLimited('members')) { ``` In case the limit check is run without direct access to the database you can override `currentCountQuery` functions for each "max" type of limit. An example usecase would be a frontend client running in a browser. A browser client can check the limit data through HTTP request and then provide that data to the limit service. Example code to do exactly that: -``` +```js const limitService = new LimitService(); let limits = { @@ -112,6 +112,17 @@ if (await limitService.checkIsOverLimit('staff')) { }; ``` +### Custom error messages +Errors returned by the limit service can be customized. When configuring the limit service through `loadLimits` method `limits` objects can specify an `error` property that is a template string. Additionally, "MaxLimit" limit type supports following variables- {{count}} and {{max}}. + +An example configuration for "MaxLimit" limit using an error template can look like following: +```json +"staff": { + "max": 5, + "error": "Your plan supports up to {{max}} staff users and you currently have {{count}}. Please upgrade to add more." +} +``` + ## Develop This is a mono repository, managed with [lerna](https://lernajs.io/).