forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntityNotFoundError.ts
More file actions
32 lines (28 loc) · 1.09 KB
/
EntityNotFoundError.ts
File metadata and controls
32 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {ObjectType} from "../common/ObjectType";
import {EntitySchema} from "../index";
/**
* Thrown when no result could be found in methods which are not allowed to return undefined or an empty set.
*/
export class EntityNotFoundError extends Error {
name = "EntityNotFound";
constructor(entityClass: ObjectType<any>|EntitySchema<any>|string, criteria: any) {
super();
Object.setPrototypeOf(this, EntityNotFoundError.prototype);
let targetName: string;
if (entityClass instanceof EntitySchema) {
targetName = entityClass.options.name;
} else if (typeof entityClass === "function") {
targetName = entityClass.name;
} else {
targetName = entityClass;
}
const criteriaString = this.stringifyCriteria(criteria);
this.message = `Could not find any entity of type "${targetName}" matching: ${criteriaString}`;
}
private stringifyCriteria(criteria: any): string {
try {
return JSON.stringify(criteria, null, 4);
} catch (e) { }
return "" + criteria;
}
}