Skip to content

Commit

Permalink
エラーハンドリングを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
gentksb committed Mar 9, 2024
1 parent 71859af commit e3e1768
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lambda/spilitwise-automation/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const handler: Handler = async (
throw new Error("環境変数が設定されていません");
}

const resuleMessage = splitRecent20Expenses({
const resuleMessage = await splitRecent20Expenses({
SPLITWISE_API_KEY_PARAMETER_NAME,
SLACK_WEBHOOK_URL,
USER1_ID,
Expand Down
9 changes: 7 additions & 2 deletions lambda/spilitwise-automation/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ export const splitRecent20Expenses = async (props: Props) => {
paths["/update_expense/{id}"]["post"]["responses"]["200"]["content"]["application/json"]
>
) => {
if (response.data.errors?.length !== 0) {
console.error(response.data.errors);
// errorが無い場合は空オブジェクトが返ってくるので、判定条件に含めておく
if (
response.data.errors === undefined ||
(response.data.errors !== undefined &&
Object.keys(response.data.errors).length > 0)
) {
console.error(response.data.errors?.toString());
await webhook.send({
text: `割り勘処理でエラー発生\n ID:${response.data.expenses?.[0].id}\n${response.data.errors?.toString()}`,
});
Expand Down
2 changes: 1 addition & 1 deletion lib/splitwise-automation-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SplitWiseAutomationStack extends Stack {
this,
"splitwise_expense_automation",
{
entry: "lambda/splitwise-automation/handler.ts",
entry: "lambda/spilitwise-automation/handler.ts",
// secret managerは無料枠がなく、常にコストがかかるので使わない
environment: {
SPLITWISE_API_KEY_PARAMETER_NAME: "splitwise API key",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"pree2e": "printf '{\"Parameters\":{\"SPLITWISE_API_KEY_PARAMETER_NAME\":\"%s\",\"SLACK_WEBHOOK_URL\":\"%s\",\"SPLITWISE_GROUP_ID\":\"%s\",\"USER1_ID\":\"%s\",\"USER2_ID\":\"%s\",\"USER1_RATE\":\"%s\",\"USER2_RATE\":\"%s\"}}' $SPLITWISE_API_KEY_PARAMETER_NAME $SLACK_WEBHOOK_URL $SPLITWISE_GROUP_ID $USER1_ID $USER2_ID $USER1_RATE $USER2_RATE > .env.json ",
"e2e": "cdk synth --no-staging && sam local invoke splitwise_expense_automation --no-event -t ./cdk.out/SplitWiseAutomationStack.template.json --env-vars .env.json",
"cdk": "cdk",
"typegen": "openapi-typescript splitwise/swagger.json -o @types/splitwise.d.ts"
"typegen": "openapi-typescript splitwise/swagger.json -o @types/splitwise.d.ts",
"deploy": "cdk deploy --require-approval never"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.133",
Expand Down

0 comments on commit e3e1768

Please sign in to comment.