Skip to content

Commit d7a1745

Browse files
authored
Merge pull request #234 from Icinga:feature/allow_custom_exception_list_for_icinga_exceptions
Adds support to allow custom exception lists
2 parents 8eb8467 + 48d2249 commit d7a1745

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

doc/31-Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1313

1414
### Enhancements
1515

16+
* [#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
17+
1618
### Bugfixes
1719

1820
## 1.4.1 (2021-03-10)

lib/icinga/exception/Exit-IcingaThrowException.psm1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function Exit-IcingaThrowException()
77
$ExceptionThrown,
88
[ValidateSet('Permission', 'Input', 'Configuration', 'Connection', 'Unhandled', 'Custom')]
99
[string]$ExceptionType = 'Unhandled',
10+
[hashtable]$ExceptionList = @{ },
1011
[string]$KnowledgeBaseId,
1112
[switch]$Force
1213
);
@@ -21,25 +22,29 @@ function Exit-IcingaThrowException()
2122
}
2223
}
2324

25+
if ($null -eq $ExceptionList -Or $ExceptionList.Count -eq 0) {
26+
$ExceptionList = $IcingaExceptions;
27+
}
28+
2429
$ExceptionMessageLib = $null;
2530
$ExceptionTypeString = '';
2631

2732
switch ($ExceptionType) {
2833
'Permission' {
2934
$ExceptionTypeString = 'Permission';
30-
$ExceptionMessageLib = $IcingaExceptions.Permission;
35+
$ExceptionMessageLib = $ExceptionList.Permission;
3136
};
3237
'Input' {
3338
$ExceptionTypeString = 'Invalid Input';
34-
$ExceptionMessageLib = $IcingaExceptions.Inputs;
39+
$ExceptionMessageLib = $ExceptionList.Inputs;
3540
};
3641
'Configuration' {
3742
$ExceptionTypeString = 'Invalid Configuration';
38-
$ExceptionMessageLib = $IcingaExceptions.Configuration;
43+
$ExceptionMessageLib = $ExceptionList.Configuration;
3944
};
4045
'Connection' {
4146
$ExceptionTypeString = 'Connection error';
42-
$ExceptionMessageLib = $IcingaExceptions.Connection;
47+
$ExceptionMessageLib = $ExceptionList.Connection;
4348
};
4449
'Unhandled' {
4550
$ExceptionTypeString = 'Unhandled';

0 commit comments

Comments
 (0)