From 48d2249605c3fbedda8584bd37cd488e7daf2fd0 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 28 Apr 2021 09:43:07 +0200 Subject: [PATCH] Adds support to allow custom exception lists --- doc/31-Changelog.md | 2 ++ lib/icinga/exception/Exit-IcingaThrowException.psm1 | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index d1bcc98..0025056 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -13,6 +13,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic ### 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 ## 1.4.1 (2021-03-10) diff --git a/lib/icinga/exception/Exit-IcingaThrowException.psm1 b/lib/icinga/exception/Exit-IcingaThrowException.psm1 index f9ac0e3..0256289 100644 --- a/lib/icinga/exception/Exit-IcingaThrowException.psm1 +++ b/lib/icinga/exception/Exit-IcingaThrowException.psm1 @@ -7,6 +7,7 @@ function Exit-IcingaThrowException() $ExceptionThrown, [ValidateSet('Permission', 'Input', 'Configuration', 'Connection', 'Unhandled', 'Custom')] [string]$ExceptionType = 'Unhandled', + [hashtable]$ExceptionList = @{ }, [string]$KnowledgeBaseId, [switch]$Force ); @@ -21,25 +22,29 @@ function Exit-IcingaThrowException() } } + if ($null -eq $ExceptionList -Or $ExceptionList.Count -eq 0) { + $ExceptionList = $IcingaExceptions; + } + $ExceptionMessageLib = $null; $ExceptionTypeString = ''; switch ($ExceptionType) { 'Permission' { $ExceptionTypeString = 'Permission'; - $ExceptionMessageLib = $IcingaExceptions.Permission; + $ExceptionMessageLib = $ExceptionList.Permission; }; 'Input' { $ExceptionTypeString = 'Invalid Input'; - $ExceptionMessageLib = $IcingaExceptions.Inputs; + $ExceptionMessageLib = $ExceptionList.Inputs; }; 'Configuration' { $ExceptionTypeString = 'Invalid Configuration'; - $ExceptionMessageLib = $IcingaExceptions.Configuration; + $ExceptionMessageLib = $ExceptionList.Configuration; }; 'Connection' { $ExceptionTypeString = 'Connection error'; - $ExceptionMessageLib = $IcingaExceptions.Connection; + $ExceptionMessageLib = $ExceptionList.Connection; }; 'Unhandled' { $ExceptionTypeString = 'Unhandled';