Open
Description
Just started using class-transformer
and tried to serialize error instances but only got empty objects.
import "reflect-metadata"
import { instanceToPlain } from "class-transformer"
const err = new RangeError("test")
const plain = instanceToPlain(err)
I expected plain
to be something like {name: "RangeError", message: "test"}
(or with a stack
trace message). Unfortunately, it returned an empty object {}
.
Inheriting from the Error
class like
class TestError extends Error {
constructor(message: string) {
super(message)
this.name = TestError
}
}
const err = new TestError("test")
const plain = instanceToPlain(err)
includes at least the name
prop (it returns {name: "TestError"}
) but has no other props at all.