Adds support to allow custom exception lists

This commit is contained in:
Lord Hepipud 2021-04-28 09:43:07 +02:00
parent 8eb8467dad
commit 48d2249605
2 changed files with 11 additions and 4 deletions

View file

@ -13,6 +13,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Enhancements ### Enhancements
* [#234](https://github.com/Icinga/icinga-powershell-framework/pull/234) Adds support to allow custom exception lists for Icinga Exceptions, making it easier for different modules to ship their own exception messages
### Bugfixes ### Bugfixes
## 1.4.1 (2021-03-10) ## 1.4.1 (2021-03-10)

View file

@ -7,6 +7,7 @@ function Exit-IcingaThrowException()
$ExceptionThrown, $ExceptionThrown,
[ValidateSet('Permission', 'Input', 'Configuration', 'Connection', 'Unhandled', 'Custom')] [ValidateSet('Permission', 'Input', 'Configuration', 'Connection', 'Unhandled', 'Custom')]
[string]$ExceptionType = 'Unhandled', [string]$ExceptionType = 'Unhandled',
[hashtable]$ExceptionList = @{ },
[string]$KnowledgeBaseId, [string]$KnowledgeBaseId,
[switch]$Force [switch]$Force
); );
@ -21,25 +22,29 @@ function Exit-IcingaThrowException()
} }
} }
if ($null -eq $ExceptionList -Or $ExceptionList.Count -eq 0) {
$ExceptionList = $IcingaExceptions;
}
$ExceptionMessageLib = $null; $ExceptionMessageLib = $null;
$ExceptionTypeString = ''; $ExceptionTypeString = '';
switch ($ExceptionType) { switch ($ExceptionType) {
'Permission' { 'Permission' {
$ExceptionTypeString = 'Permission'; $ExceptionTypeString = 'Permission';
$ExceptionMessageLib = $IcingaExceptions.Permission; $ExceptionMessageLib = $ExceptionList.Permission;
}; };
'Input' { 'Input' {
$ExceptionTypeString = 'Invalid Input'; $ExceptionTypeString = 'Invalid Input';
$ExceptionMessageLib = $IcingaExceptions.Inputs; $ExceptionMessageLib = $ExceptionList.Inputs;
}; };
'Configuration' { 'Configuration' {
$ExceptionTypeString = 'Invalid Configuration'; $ExceptionTypeString = 'Invalid Configuration';
$ExceptionMessageLib = $IcingaExceptions.Configuration; $ExceptionMessageLib = $ExceptionList.Configuration;
}; };
'Connection' { 'Connection' {
$ExceptionTypeString = 'Connection error'; $ExceptionTypeString = 'Connection error';
$ExceptionMessageLib = $IcingaExceptions.Connection; $ExceptionMessageLib = $ExceptionList.Connection;
}; };
'Unhandled' { 'Unhandled' {
$ExceptionTypeString = 'Unhandled'; $ExceptionTypeString = 'Unhandled';