1
1
import { ConnectionManager , Repository , TreeRepository , MongoRepository } from "typeorm" ;
2
2
import { Container } from "typedi" ;
3
3
4
+ import { EntityTypeMissingError } from "../errors/EntityTypeMissingError" ;
5
+ import { PropertyTypeMissingError } from "../errors/PropertyTypeMissingError" ;
6
+ import { ParamTypeMissingError } from "../errors/ParamTypeMissingError" ;
7
+
4
8
/**
5
9
* Helper to avoid V8 compilation of anonymous function on each call of decorator.
6
10
*/
@@ -126,27 +130,15 @@ export function OrmRepository(entityTypeOrConnectionName?: Function|string, para
126
130
if ( index !== undefined ) {
127
131
const paramTypes : Function [ ] | undefined = Reflect . getOwnMetadata ( "design:paramtypes" , object , propertyName ) ;
128
132
if ( ! paramTypes || ! paramTypes [ index ] ) {
129
- throw new Error (
130
- `Cannot get reflected type for a "${ propertyName } " method's ${ index + 1 } . parameter of ${ object . constructor . name } class. ` +
131
- `Make sure you have turned on an "emitDecoratorMetadata": true, option in tsconfig.json. ` +
132
- `and that you have imported "reflect-metadata" on top of the main entry file in your application.` +
133
- `And make sure that you have annotated the property type correctly with: ` +
134
- `Repository, MongoRepository, TreeRepository or custom repository class type.`
135
- ) ;
133
+ throw new ParamTypeMissingError ( object , propertyName , index ) ;
136
134
}
137
135
repositoryType = paramTypes [ index ] ;
138
136
}
139
137
// if the parameter has been aplied to class property
140
138
else {
141
139
const propertyType : Function | undefined = Reflect . getOwnMetadata ( "design:type" , object , propertyName ) ;
142
140
if ( ! propertyType ) {
143
- throw new Error (
144
- `Cannot get reflected type for a property "${ propertyName } " of ${ object . constructor . name } class. ` +
145
- `Make sure you have turned on an "emitDecoratorMetadata": true, option in tsconfig.json ` +
146
- `and that you have imported "reflect-metadata" on top of the main entry file in your application.` +
147
- `And make sure that you have annotated the property type correctly with: ` +
148
- `Repository, MongoRepository, TreeRepository or custom repository class type.`
149
- ) ;
141
+ throw new PropertyTypeMissingError ( object , propertyName ) ;
150
142
}
151
143
repositoryType = propertyType ;
152
144
}
@@ -156,16 +148,7 @@ export function OrmRepository(entityTypeOrConnectionName?: Function|string, para
156
148
case MongoRepository :
157
149
case TreeRepository :
158
150
if ( ! entityType ) {
159
- throw new Error (
160
- `Missing "entityType" parameter of "@OrmRepository" decorator ` +
161
- index !== undefined
162
- ? `for a "${ propertyName } " method's ${ index ! + 1 } . parameter of ${ object . constructor . name } class. `
163
- : `for a property "${ propertyName } " of ${ object . constructor . name } class. `
164
- +
165
- `For injecting Repository, MongoRepository or TreeRepository, ` +
166
- `you have to specify the entity type due to TS reflection limitation - ` +
167
- `"entityType" parameter can be ommited only for custom repositories.`
168
- ) ;
151
+ throw new EntityTypeMissingError ( object , propertyName , index ) ;
169
152
}
170
153
}
171
154
0 commit comments