Skip to content

Commit

Permalink
fix: do not throw error if permission for node-robot permission creat…
Browse files Browse the repository at this point in the history
…ion does not exist
  • Loading branch information
tada5hi committed Nov 12, 2024
1 parent d511fd0 commit eac34b5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/server-core/src/services/node-robot/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* view the LICENSE file that was distributed with this source code.
*/

import type { Robot } from '@authup/core-kit';
import type { Permission, Robot } from '@authup/core-kit';
import { PermissionName } from '@privateaim/kit';
import type { AuthupClient } from '@privateaim/server-kit';
import { useAuthupClient } from '@privateaim/server-kit';
import { useAuthupClient, useLogger } from '@privateaim/server-kit';
import { isClientErrorWithStatusCode } from 'hapic';
import type { NodeEntity } from '../../domains';

Expand Down Expand Up @@ -100,7 +100,19 @@ export class NodeRobotService {
continue;
}

const permission = await this.authup.permission.getOne(permissionNames[i]);
let permission : Permission;

try {
permission = await this.authup.permission.getOne(permissionNames[i]);
} catch (e) {
if (!isClientErrorWithStatusCode(e, 404)) {
throw e;
}

useLogger()
.warn(`The node-robot permission could not be created, due non existing permission ${permissionNames[i]}.`);
}

await this.authup.robotPermission.create({
robot_id: robot.id,
permission_id: permission.id,
Expand Down

0 comments on commit eac34b5

Please sign in to comment.