Last active
February 10, 2024 09:43
-
-
Save SchreiberLars/dbb920d4ebd3bdb5ee1204c586f1daa8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(IDCustErr as number)=> | |
let | |
//IDCustErr = 5, /* for debugging purposes */ | |
// ============ START: Define your list of custom error records here ==================== | |
ListCustomErrors = { | |
//Custom error #1: The only permissible tax rates are as follows 7% and 19% | |
[ | |
CustErrID = 1, | |
reason ="Illegal tax rate", | |
message = "The only allowed tax rates are 7% and 19%!", | |
detail = "Make sure in your data source, that only those 2 tax rates are included!", | |
InternalDescription = "When ever another tax rate comes up, throw this error record" | |
], | |
//Custom error #2: | |
[ | |
CustErrID = 2, | |
reason ="Reason Error 2", | |
message = "Message Error 2", | |
detail = "Details Error 2", | |
InternalDescription = "INternal Description Error 2" | |
] | |
/* | |
Define as many other custom error records, as you want/ need here | |
*/ | |
}, | |
// ============ END: Define your list of custom error records here ==================== | |
//Convert the list into a table | |
ListToTable = Table.FromList(ListCustomErrors, Splitter.SplitByNothing(), null, null, ExtraValues.Error), | |
//Expand the table | |
ExpandColumn = Table.ExpandRecordColumn(ListToTable, "Column1", {"CustErrID", "reason", "message", "detail", | |
"InternalDescription"}, {"CustErrID", "reason", "message", "detail", "InternalDescription"}), | |
//This step filters the table down to the record, which has the custom error ID that you passed to the function with 'IDCustErr' | |
FilterForCustErrID = | |
try | |
//Try to call the CustErrID | |
Table.SelectRows(ExpandColumn, each ([CustErrID] = IDCustErr)){0} | |
otherwise | |
//if the CustErrID doesn't exist, throw the following error | |
error Error.Record( "Error ID not existing!", "The error ID doesn't exist! Use an existing one!"), | |
//Throw the custom error | |
Result = error Error.Record( FilterForCustErrID[reason], FilterForCustErrID[message], FilterForCustErrID[detail] ) | |
in | |
Result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment