Skip to content

Commit

Permalink
Update CharacterCount to use formatErrorMessage
Browse files Browse the repository at this point in the history
It aligns the `ConfigError` it throws with the rest of the errors thrown by components
  • Loading branch information
romaricpascal committed Sep 27, 2024
1 parent 2d93945 commit 7da5786
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { closestAttributeValue } from '../../common/closest-attribute-value.mjs'
import { mergeConfigs, validateConfig } from '../../common/index.mjs'
import {
formatErrorMessage,
mergeConfigs,
validateConfig
} from '../../common/index.mjs'
import { normaliseDataset } from '../../common/normalise-dataset.mjs'
import { ConfigError, ElementError } from '../../errors/index.mjs'
import { GOVUKFrontendComponent } from '../../govuk-frontend-component.mjs'
Expand Down Expand Up @@ -115,7 +119,7 @@ export class CharacterCount extends GOVUKFrontendComponent {
// Check for valid config
const errors = validateConfig(CharacterCount.schema, this.config)
if (errors[0]) {
throw new ConfigError(`Character count: ${errors[0]}`)
throw new ConfigError(formatErrorMessage(CharacterCount, errors[0]))
}

this.i18n = new I18n(this.config.i18n, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ describe('Character count', () => {
cause: {
name: 'ConfigError',
message:
'Character count: Either "maxlength" or "maxwords" must be provided'
'govuk-character-count: Either "maxlength" or "maxwords" must be provided'
}
})
})
Expand Down

0 comments on commit 7da5786

Please sign in to comment.