Просмотр исходного кода

tried to res send with 'errors object'

kaori 4 лет назад
Родитель
Сommit
7ba726469f

+ 11 - 2
packages/slackbot-proxy/src/controllers/slack.ts

@@ -141,7 +141,7 @@ export class SlackCtrl {
 
 
     // Send response immediately to avoid opelation_timeout error
     // Send response immediately to avoid opelation_timeout error
     // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
     // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
-    res.send();
+    // res.send();
 
 
     // pass
     // pass
     if (body.ssl_check != null) {
     if (body.ssl_check != null) {
@@ -154,10 +154,19 @@ export class SlackCtrl {
 
 
     const payload = JSON.parse(body.payload);
     const payload = JSON.parse(body.payload);
     const callBackId = payload?.view?.callback_id;
     const callBackId = payload?.view?.callback_id;
+    const { type } = payload;
+    console.log('typehoge', type);
+
 
 
     // register
     // register
     if (callBackId === 'register') {
     if (callBackId === 'register') {
-      await this.registerService.insertOrderRecord(this.orderRepository, installation, payload);
+      const insertResults = await this.registerService.insertOrderRecord(this.orderRepository, installation, payload);
+
+      console.log('insertResults', insertResults);
+      if (insertResults != null && insertResults.response_action === 'errors') {
+        return res.send(insertResults.response_action);
+      }
+
       await this.registerService.notifyServerUriToSlack(authorizeResult, payload);
       await this.registerService.notifyServerUriToSlack(authorizeResult, payload);
       return;
       return;
     }
     }

+ 8 - 9
packages/slackbot-proxy/src/services/RegisterService.ts

@@ -46,7 +46,7 @@ export class RegisterService implements GrowiCommandProcessor {
   async insertOrderRecord(
   async insertOrderRecord(
       // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
       // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
       orderRepository: OrderRepository, installation: Installation | undefined, payload: any,
       orderRepository: OrderRepository, installation: Installation | undefined, payload: any,
-  ): Promise<void> {
+  ): Promise<any> {
     const inputValues = payload.view.state.values;
     const inputValues = payload.view.state.values;
     const growiUrl = inputValues.growiUrl.contents_input.value;
     const growiUrl = inputValues.growiUrl.contents_input.value;
     const tokenPtoG = inputValues.tokenPtoG.contents_input.value;
     const tokenPtoG = inputValues.tokenPtoG.contents_input.value;
@@ -59,17 +59,16 @@ export class RegisterService implements GrowiCommandProcessor {
       return url.match(/^(https?:\/\/)/);
       return url.match(/^(https?:\/\/)/);
     };
     };
 
 
-    console.log('urlValidate()', isUrl(growiUrl));
+    console.log('isUrl(growiUrl)', isUrl(growiUrl));
 
 
     if (isUrl(growiUrl) == null) {
     if (isUrl(growiUrl) == null) {
-      // return {
-      //   response_action: 'errors',
-      //   errors: {
-      //     block_id: 'growiUrl',
-      //   },
-      // };
       console.log('urlは正しくありません');
       console.log('urlは正しくありません');
-      return;
+      return {
+        response_action: 'errors',
+        errors: {
+          block_id: 'growiUrl',
+        },
+      };
     }
     }
     console.log('urlは正常');
     console.log('urlは正常');