瀏覽代碼

improve error handling

Yuki Takei 5 年之前
父節點
當前提交
df8bdf80f4
共有 1 個文件被更改,包括 6 次插入4 次删除
  1. 6 4
      packages/slackbot-proxy/src/middlewares/authorizer.ts

+ 6 - 4
packages/slackbot-proxy/src/middlewares/authorizer.ts

@@ -50,13 +50,14 @@ export class AuthorizeCommandMiddleware implements IMiddleware {
       result = await this.installerService.installer.authorize(query);
 
       if (result.botToken == null) {
-        throw new Error(`The installation for the team(${teamId || enterpriseId}) has no botToken`);
+        res.writeHead(403, `The installation for the team(${teamId || enterpriseId}) has no botToken`);
+        return res.end();
       }
     }
     catch (e) {
       this.logger.error(e.message);
 
-      res.writeHead(403, e.message);
+      res.writeHead(500, e.message);
       return res.end();
     }
 
@@ -109,13 +110,14 @@ export class AuthorizeInteractionMiddleware implements IMiddleware {
       result = await this.installerService.installer.authorize(query);
 
       if (result.botToken == null) {
-        throw new Error(`The installation for the team(${teamId || enterpriseId}) has no botToken`);
+        res.writeHead(403, `The installation for the team(${teamId || enterpriseId}) has no botToken`);
+        return res.end();
       }
     }
     catch (e) {
       this.logger.error(e.message);
 
-      res.writeHead(403, e.message);
+      res.writeHead(500, e.message);
       return res.end();
     }