@modular-rest/server 1.11.0 → 1.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-rest/server",
3
- "version": "1.11.0",
3
+ "version": "1.11.2",
4
4
  "description": "a nodejs module based on KOAJS for developing Rest-APIs in a modular solution.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -43,4 +43,4 @@
43
43
  "@types/koa__cors": "^5.0.0",
44
44
  "typescript": "^5.3.3"
45
45
  }
46
- }
46
+ }
@@ -26,7 +26,7 @@ functionRouter.post(`/run`, middleware.auth, async (ctx) => {
26
26
  const result = await service.runFunction(name, args, ctx.state.user);
27
27
  ctx.body = JSON.stringify(reply("s", { data: result }));
28
28
  } catch (e) {
29
- ctx.throw(500, JSON.stringify(reply("e", { e: e.message })));
29
+ ctx.throw(400, JSON.stringify(reply("e", { e: e.message })));
30
30
  }
31
31
  });
32
32
 
@@ -44,16 +44,21 @@ function runFunction(name, args, user) {
44
44
  user.hasPermission(permissionType)
45
45
  );
46
46
 
47
- if (!hasPermission) {
47
+ if (!!hasPermission) {
48
48
  reject(
49
- new Error(`User does not have permission to run function ${name}`)
49
+ new Error(`User does not have permission to run function ${name}:
50
+ Function permissions: ${func.permissionTypes}
51
+ User permissions: ${
52
+ user.permissionGroup().permissionGroup.validPermissionTypes
53
+ }
54
+ `)
50
55
  );
51
- }
52
-
53
- try {
54
- resolve(func.callback(args));
55
- } catch (e) {
56
- reject(e);
56
+ } else {
57
+ try {
58
+ resolve(func.callback(args));
59
+ } catch (e) {
60
+ reject(e);
61
+ }
57
62
  }
58
63
  });
59
64
  }