Issue with error-text of custom error-code
Hi,
I am trying to generate a custom error-code using the following code
Class ISG.CommonBilling.Service.Test1 Extends EnsLib.HL7.Operation.TCPOperation
{
ClassMethod khalid() As %Status
{
Set tSC=$$$ERROR("10001","I am here")
write $$$GETERRORCODE(tSC)_$char(13,10)
write $SYSTEM.Status.GetErrorText(tSC)
}
}
And here is the output:
KINDRED>do ##class(ISG.CommonBilling.Service.Test1).khalid()
10001
ERROR #10001: Unknown status code: 10001 (I am here)
QUERY: Is there any way I can remove the part "Unknown status code: 10001 (...)" in the error-text?
Thanks in advance,
Khalid
Try generating an error with code 5001 ($$$GeneralError, "your custom message").
This will give you an "#ERROR 5001: your custom message", $replace that "#ERROR 5001:" part to "" using GetErrorText.
Note that if you have multiple errors inside a single status you'll need to fetch and $replace them individually.
That's because I don't think you can generate custom error codes. I would delegate the errors to your application layer instead.
As I wanted to get the custom error-code along with the custom error-text, I used the regex-class "%Regex.Matcher" to pull the content/custom-text within the parenthesis in the error-text. This served my purpose. Thanks for looking into it... :-)
Here is the modified code:
Output:
Dammit, I would downvote myself if I could. XD
The translation was already done: Localization in Caché DBMS
Here's how you can define your own errors.
Create messages.xml with your error messages:
Import it into Cache:
It will result in two globals being populated:
Next we generate CustomErrors include file (docs):
Here's what CustomErrors.inc looks like:
Now we can use new custom errors:
Results in:
Text is not mine, translated from here.