mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
chore: log descriptive errors from the Entity Listener Metadata (#11234)
* Added logging to the Entity Listener Metadata as it will throw an error (entity[this.propertyName] is not a function), which is not a descriptive error and makes it hard for users to debug their programs * Bound the entity to the Entity Method * Update src/metadata/EntityListenerMetadata.ts --------- Co-authored-by: Lucian Mocanu <alumni@users.noreply.github.com> Co-authored-by: Mike Guida <mike@mguida.com>
This commit is contained in:
parent
046aebe696
commit
184f463ed7
@ -75,8 +75,30 @@ export class EntityListenerMetadata {
|
||||
* Executes listener method of the given entity.
|
||||
*/
|
||||
execute(entity: ObjectLiteral) {
|
||||
if (!this.embeddedMetadata) return entity[this.propertyName]()
|
||||
// Check if the Embedded Metadata does not exist
|
||||
if (!this.embeddedMetadata) {
|
||||
// Get the Entity's Method
|
||||
const entityMethod = entity[this.propertyName]
|
||||
|
||||
// Check if the Entity Method does not exist
|
||||
if (!entityMethod)
|
||||
throw new Error(
|
||||
`Entity listener method "${this.propertyName}" does not exist in entity "${entity.constructor.name}".`,
|
||||
)
|
||||
|
||||
// Check if the Entity Method is not a function
|
||||
if (typeof entityMethod !== "function")
|
||||
throw new Error(
|
||||
`Entity listener method "${this.propertyName}" in entity "${
|
||||
entity.constructor.name
|
||||
}" must be a function but got "${typeof entityMethod}".`,
|
||||
)
|
||||
|
||||
// Call and return the Entity Method
|
||||
return entityMethod.call(entity)
|
||||
}
|
||||
|
||||
// Call the Embedded Method
|
||||
this.callEntityEmbeddedMethod(
|
||||
entity,
|
||||
this.embeddedMetadata.propertyPath.split("."),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user