Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Syntax
Error.Record(
reason as text,
optional message as nullable text,
optional detail as any,
optional parameters as nullable list,
optional errorCode as nullable text
) as record
About
Returns an error record from the provided text values for reason, mesage, detail, and error code.
reason: The high-level cause of the error.message: (Optional) A description of the error.detail: (Optional) Additional detailed information about the error.parameters: (Optional) A list of values that provide additional context for the error, typically used for diagnostics or programmatic handling.errorCode: (Optional) An identifier for the error.
Example 1
Handle a divide by zero error.
Usage
let
input = 100,
divisor = 0,
result = try if divisor = 0 then
error Error.Record(
"DivideByZero",
"You attempted to divide by zero."
)
else
input / divisor
in
result
Output
[
HasError = true,
Error =
[
Reason = "DivideByZero",
Message = "You attempted to divide by zero.",
Detail = null,
Message.Format = null,
Message.Parameters = null,
ErrorCode = null
]
]
Example 2
Handle an entry with a non-existent customer ID error. If no error occurs, indicate a successful entry.
Usage
let
CustomerId = 12345,
result = try if CustomerId > 9999 then
error Error.Record(
"CustomerNotFound",
Text.Format("Customer ID #{0} wasn't found.", {CustomerId}),
"Customer doesn't exist.",
{
Text.Format("Invalid ID = #{0}", {CustomerId}),
"Valid IDs: https://api.contoso.com/customers"
},
"ERR404"
)
else CustomerId
in
result
Output
[
HasError = true,
Error = [
Reason = "CustomerNotFound",
Message = "Customer ID 12345 wasn't found.",
Detail = "Customer doesn't exist.",
Message.Format = "Customer ID 12345 wasn't found.",
Message.Parameters = {
"Invalid ID = 12345",
"Valid IDs: https://api.contoso.com/customers"
},
ErrorCode = "ERR404"
]
]