|
18 | 18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
19 | 19 | */ |
20 | 20 |
|
| 21 | +const APIError = require("../../api/APIError"); |
21 | 22 | const { get_user, get_app } = require("../../helpers"); |
22 | 23 | const BaseService = require("../BaseService"); |
23 | 24 | const { DB_WRITE } = require("../database/consts"); |
@@ -401,6 +402,12 @@ class PermissionService extends BaseService { |
401 | 402 |
|
402 | 403 | let app = await get_app({ uid: app_uid }); |
403 | 404 | if ( ! app ) app = await get_app({ name: app_uid }); |
| 405 | + |
| 406 | + if ( ! app ) { |
| 407 | + throw APIError.create('entity_not_found', null, { |
| 408 | + identifier: 'app:' + app_uid, |
| 409 | + }); |
| 410 | + } |
404 | 411 |
|
405 | 412 | const app_id = app.id; |
406 | 413 |
|
@@ -466,6 +473,11 @@ class PermissionService extends BaseService { |
466 | 473 |
|
467 | 474 | let app = await get_app({ uid: app_uid }); |
468 | 475 | if ( ! app ) app = await get_app({ name: app_uid }); |
| 476 | + if ( ! app ) { |
| 477 | + throw APIError.create('entity_not_found', null, { |
| 478 | + identifier: 'app' + app_uid, |
| 479 | + }) |
| 480 | + } |
469 | 481 | const app_id = app.id; |
470 | 482 |
|
471 | 483 | // DELETE permission |
@@ -570,7 +582,9 @@ class PermissionService extends BaseService { |
570 | 582 | permission = await this._rewrite_permission(permission); |
571 | 583 | const user = await get_user({ username }); |
572 | 584 | if ( ! user ) { |
573 | | - throw new Error('user not found'); |
| 585 | + throw APIError.create('user_does_not_exist', null, { |
| 586 | + username, |
| 587 | + }) |
574 | 588 | } |
575 | 589 |
|
576 | 590 | // Don't allow granting permissions to yourself |
@@ -633,7 +647,9 @@ class PermissionService extends BaseService { |
633 | 647 | const svc_group = this.services.get('group'); |
634 | 648 | const group = await svc_group.get({ uid: gid }); |
635 | 649 | if ( ! group ) { |
636 | | - throw new Error('group not found'); |
| 650 | + throw APIError.create('entity_not_found', null, { |
| 651 | + identifier: 'group:' + gid, |
| 652 | + }); |
637 | 653 | } |
638 | 654 |
|
639 | 655 | await this.db.write( |
@@ -688,7 +704,11 @@ class PermissionService extends BaseService { |
688 | 704 |
|
689 | 705 | const user = await get_user({ username }); |
690 | 706 | if ( ! user ) { |
691 | | - throw new Error('user not found'); |
| 707 | + if ( ! user ) { |
| 708 | + throw APIError.create('user_does_not_exist', null, { |
| 709 | + username, |
| 710 | + }) |
| 711 | + } |
692 | 712 | } |
693 | 713 |
|
694 | 714 | // DELETE permission |
@@ -738,7 +758,9 @@ class PermissionService extends BaseService { |
738 | 758 | const svc_group = this.services.get('group'); |
739 | 759 | const group = await svc_group.get({ uid: gid }); |
740 | 760 | if ( ! group ) { |
741 | | - throw new Error('group not found'); |
| 761 | + throw APIError.create('entity_not_found', null, { |
| 762 | + identifier: 'group:' + gid, |
| 763 | + }); |
742 | 764 | } |
743 | 765 |
|
744 | 766 | // DELETE permission |
|
0 commit comments