I am dealing with a scenario where my function might throw an object as an error in TypeScript. The challenge is that the object being thrown is not of type Error
. How can I effectively handle this situation?
For example:
function throwsSomeError() {
throw { code: 10, message: 'error' }
}
try {
throwsSomeError()
} catch (error: unknown) {
const message = error?.message;
// ^^ Object is of type 'unknown'.(2571)
}