Skip to content

Commit

Permalink
Merge pull request #358 from syou6162/define_esa_error_type
Browse files Browse the repository at this point in the history
Esaのresponse errorの型を定義する
  • Loading branch information
syou6162 committed May 4, 2022
2 parents 6a27f18 + 2f5fce3 commit f99cf22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/check_firebase_cloud_function.yaml
@@ -0,0 +1,18 @@
name: Firebase Cloud Function部分の確認

on: [push]

jobs:
check_firebase_hosting:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '12'
- run: npm install
- run: npm install
working-directory: ./functions
- run: npm --prefix functions run lint
- run: npm --prefix functions run build
10 changes: 8 additions & 2 deletions functions/src/index.ts
Expand Up @@ -52,6 +52,12 @@ export type EsaTags = {
tags: Tag[]
}

// ref: https://docs.esa.io/posts/102#%E3%82%A8%E3%83%A9%E3%83%BC%E3%83%AC%E3%82%B9%E3%83%9D%E3%83%B3%E3%82%B9
type EsaErrorResponse = {
error: string;
message: string;
}

function transformTitle(oldTitle: string, newTitle: string): string {
const result = Array.from(new Set(oldTitle.split(/,\s?|、/).concat(newTitle.split(/,\s?|、/))));
if (JSON.stringify(result) === JSON.stringify(['日報'])) {
Expand Down Expand Up @@ -86,7 +92,7 @@ async function createOrUpdatePost(
},
}).then((res: AxiosResponse<EsaPost>) => {
return res.data;
}).catch((err: AxiosError) => {
}).catch((err: AxiosError<EsaErrorResponse>) => {
throw new functions.https.HttpsError('invalid-argument', `${err.response?.data.error}: ${err.response?.data.message}`);
});
}
Expand All @@ -102,7 +108,7 @@ async function createOrUpdatePost(
},
}).then((res: AxiosResponse<EsaPost>) => {
return res.data;
}).catch((err: AxiosError) => {
}).catch((err: AxiosError<EsaErrorResponse>) => {
throw new functions.https.HttpsError('invalid-argument', `${err.response?.data.error}: ${err.response?.data.message}`);
});
}
Expand Down

0 comments on commit f99cf22

Please sign in to comment.