Skip to content

Commit

Permalink
fix(grant): throw 400 error status code while invalid params
Browse files Browse the repository at this point in the history
  • Loading branch information
isuvorov committed May 12, 2022
1 parent dd75908 commit 563452c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/grant/src/GrantModule.js
Expand Up @@ -57,8 +57,8 @@ export class GrantModule extends Module {
} else if (args.length === 3) {
[action, rule, ctx] = args;
} else {
if (args.length) throw new Err('grant.tooMuchArgs', 'getArgs: too much args');
throw new Err('grant.emptyArgs', 'getArgs: empty args');
if (args.length) throw new Err('grant.tooMuchArgs', 'getArgs: too much args', { status: 400 });
throw new Err('grant.emptyArgs', 'getArgs: empty args', { status: 400 });
}
if (typeof rule === 'string') {
rule = { action: rule };
Expand Down Expand Up @@ -109,8 +109,8 @@ export class GrantModule extends Module {
}
async can(...args) {
const [rules, ctx] = await this.getArgs(...args);
if (rules.length > 1) throw new Err('grant.tooMuchArgs', 'getArgs: too much args');
if (rules.length < 1) throw new Err('grant.emptyArgs', 'getArgs: empty args');
if (rules.length > 1) throw new Err('grant.tooMuchArgs', 'getArgs: too much args', { status: 400 });
if (rules.length < 1) throw new Err('grant.emptyArgs', 'getArgs: empty args', { status: 400 });
const [rule] = rules;
if (this.debug) this.log.trace('can', rule.action);
return this.getRule(rule, ctx);
Expand Down Expand Up @@ -145,7 +145,7 @@ export class GrantModule extends Module {
});
const res = fromPairs(pairs);
if (this.debug) this.log.trace('canGroup res', res);
return res
return res;

// const res = {};
// pairs.forEach((pair) => {
Expand All @@ -170,7 +170,7 @@ export class GrantModule extends Module {
const can = (action) => {
if (this.debug) this.log.trace('grantCache.can', action);
if (res[action] == null) {
this.log.warn('?grantCache.can', 'cant find rule in grantCache', { action }, {res});
this.log.warn('?grantCache.can', 'cant find rule in grantCache', { action }, { res });
return null;
}
return get(res, action);
Expand Down

0 comments on commit 563452c

Please sign in to comment.