Skip to content

Commit adba2c7

Browse files
committed
Added error message in firstOrFail
1 parent 34ce3b8 commit adba2c7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/model/EntityQuery.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,12 @@ export default class EntityQuery<T = any>
451451
}
452452
}
453453

454-
async firstOrFail(): Promise<T> {
455-
for await(const iterator of this.limit(1).enumerate()) {
456-
return iterator;
454+
async firstOrFail(errorMessage = `No records found for ${this.type?.name || "Table"}`): Promise<T> {
455+
const first = await this.first();
456+
if (first) {
457+
return first;
457458
}
458-
throw new Error(`No records found for ${this.type?.name || "Table"}`);
459+
throw new Error(errorMessage);
459460
}
460461

461462
async first(): Promise<T> {

0 commit comments

Comments
 (0)