diff --git a/public/app/features/manage-dashboards/services/ValidationSrv.ts b/public/app/features/manage-dashboards/services/ValidationSrv.ts index 0e4c570d4f67..4b3002916380 100644 --- a/public/app/features/manage-dashboards/services/ValidationSrv.ts +++ b/public/app/features/manage-dashboards/services/ValidationSrv.ts @@ -5,6 +5,15 @@ const hitTypes = { DASHBOARD: 'dash-db', }; +class ValidationError extends Error { + type: string; + + constructor(type: string, message: string) { + super(message); + this.type = type; + } +} + export class ValidationSrv { rootName = 'general'; @@ -21,17 +30,11 @@ export class ValidationSrv { const nameLowerCased = name.toLowerCase(); if (name.length === 0) { - throw { - type: 'REQUIRED', - message: 'Name is required', - }; + throw new ValidationError('REQUIRED', 'Name is required'); } if (folderId === 0 && nameLowerCased === this.rootName) { - throw { - type: 'EXISTING', - message: 'This is a reserved name and cannot be used for a folder.', - }; + throw new ValidationError('EXISTING', 'This is a reserved name and cannot be used for a folder.'); } const promises = []; @@ -51,10 +54,7 @@ export class ValidationSrv { for (const hit of hits) { if (nameLowerCased === hit.title.toLowerCase()) { - throw { - type: 'EXISTING', - message: existingErrorMessage, - }; + throw new ValidationError('EXISTING', existingErrorMessage); } }