Skip to content

Commit 18e8650

Browse files
committed
fix: allow beforeDataSourceRequest hook to return an { ok: false }
1 parent ca5af25 commit 18e8650

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

adminforth/modules/restApi.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,12 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
748748
},
749749
adminforth: this.adminforth,
750750
});
751-
if (!resp || (!resp.ok && !resp.error)) {
752-
throw new Error(`Hook must return object with {ok: true} or { error: 'Error' } `);
751+
if (!resp || typeof resp.ok !== 'boolean') {
752+
throw new Error(`Hook beforeSave must return { ok: boolean, error?: string | null }`);
753+
}
754+
if (resp.ok === false && !resp.error) {
755+
return { error: resp.error ?? 'Operation aborted by hook' };
753756
}
754-
755757
if (resp.error) {
756758
return { error: resp.error };
757759
}

0 commit comments

Comments
 (0)