|
@@ -2,6 +2,7 @@ import {
|
|
|
Controller, Get, Post, Inject, Req, Res, UseBefore, PathParams,
|
|
Controller, Get, Post, Inject, Req, Res, UseBefore, PathParams,
|
|
|
} from '@tsed/common';
|
|
} from '@tsed/common';
|
|
|
import axios from 'axios';
|
|
import axios from 'axios';
|
|
|
|
|
+import createError from 'http-errors';
|
|
|
|
|
|
|
|
import { WebAPICallOptions, WebAPICallResult } from '@slack/web-api';
|
|
import { WebAPICallOptions, WebAPICallResult } from '@slack/web-api';
|
|
|
|
|
|
|
@@ -89,7 +90,7 @@ export class GrowiToSlackCtrl {
|
|
|
const { tokenGtoPs } = req;
|
|
const { tokenGtoPs } = req;
|
|
|
|
|
|
|
|
if (tokenGtoPs.length !== 1) {
|
|
if (tokenGtoPs.length !== 1) {
|
|
|
- return res.status(400).send({ message: 'installation is invalid' });
|
|
|
|
|
|
|
+ throw createError(400, 'installation is invalid');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const tokenGtoP = tokenGtoPs[0];
|
|
const tokenGtoP = tokenGtoPs[0];
|
|
@@ -106,7 +107,7 @@ export class GrowiToSlackCtrl {
|
|
|
|
|
|
|
|
const token = relation.installation.data.bot?.token;
|
|
const token = relation.installation.data.bot?.token;
|
|
|
if (token == null) {
|
|
if (token == null) {
|
|
|
- return res.status(400).send({ message: 'installation is invalid' });
|
|
|
|
|
|
|
+ throw createError(400, 'installation is invalid');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -114,12 +115,12 @@ export class GrowiToSlackCtrl {
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
logger.error(err);
|
|
|
- return res.status(400).send({ message: `failed to request to GROWI. err: ${err.message}` });
|
|
|
|
|
|
|
+ throw createError(400, `failed to request to GROWI. err: ${err.message}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const status = await getConnectionStatus(token);
|
|
const status = await getConnectionStatus(token);
|
|
|
if (status.error != null) {
|
|
if (status.error != null) {
|
|
|
- return res.status(400).send({ message: `failed to get connection. err: ${status.error}` });
|
|
|
|
|
|
|
+ throw createError(400, `failed to get connection. err: ${status.error}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return res.send({ relation, slackBotToken: token });
|
|
return res.send({ relation, slackBotToken: token });
|
|
@@ -133,7 +134,7 @@ export class GrowiToSlackCtrl {
|
|
|
.getOne();
|
|
.getOne();
|
|
|
|
|
|
|
|
if (order == null || order.isExpired()) {
|
|
if (order == null || order.isExpired()) {
|
|
|
- return res.status(400).send({ message: 'order has expired or does not exist.' });
|
|
|
|
|
|
|
+ throw createError(400, 'order has expired or does not exist.');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Access the GROWI URL saved in the Order record and check if the GtoP token is valid.
|
|
// Access the GROWI URL saved in the Order record and check if the GtoP token is valid.
|
|
@@ -142,19 +143,19 @@ export class GrowiToSlackCtrl {
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
logger.error(err);
|
|
|
- return res.status(400).send({ message: `failed to request to GROWI. err: ${err.message}` });
|
|
|
|
|
|
|
+ throw createError(400, `failed to request to GROWI. err: ${err.message}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
logger.debug('order found', order);
|
|
logger.debug('order found', order);
|
|
|
|
|
|
|
|
const token = order.installation.data.bot?.token;
|
|
const token = order.installation.data.bot?.token;
|
|
|
if (token == null) {
|
|
if (token == null) {
|
|
|
- return res.status(400).send({ message: 'installation is invalid' });
|
|
|
|
|
|
|
+ throw createError(400, 'installation is invalid');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const status = await getConnectionStatus(token);
|
|
const status = await getConnectionStatus(token);
|
|
|
if (status.error != null) {
|
|
if (status.error != null) {
|
|
|
- return res.status(400).send({ message: `failed to get connection. err: ${status.error}` });
|
|
|
|
|
|
|
+ throw createError(400, `failed to get connection. err: ${status.error}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
logger.debug('relation test is success', order);
|
|
logger.debug('relation test is success', order);
|