Skip to content

Function: exceptionParams() ​

exceptionParams(exception): unknown[] | Record<string, unknown> | undefined

Read the parameters an exception's message template was formatted with (new XxxException('Order {id} not found', {id: 1})), to translate the message into another language with the same values.

Parameters ​

exception ​

Error

The error to read; any error is accepted.

Returns ​

unknown[] | Record<string, unknown> | undefined

The object given as the single parameter, the parameters as an array when several (or a single non-object one) were given, or undefined when the exception was created without parameters or is not an Exception.

Example ​

typescript
import {Exception, exceptionParams} from 'lakutata'

class OrderNotFoundException extends Exception {
    public errno: string = 'E_ORDER_NOT_FOUND'
}

const error: OrderNotFoundException = new OrderNotFoundException('Order {id} not found', {id: 1})
console.log(error.message) //Order 1 not found
console.log(exceptionParams(error)) //{id: 1}

Released under the MIT License.