File tree 3 files changed +31
-2
lines changed
3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,11 @@ import { getFileSystemRepo } from "../lib/get-file-system-repo";
6
6
import { getQiitaApiInstance } from "../lib/get-qiita-api-instance" ;
7
7
import { syncArticlesFromQiita } from "../lib/sync-articles-from-qiita" ;
8
8
import { validateItem } from "../lib/validators/item-validator" ;
9
- import { Item } from "../qiita-api" ;
9
+ import {
10
+ Item ,
11
+ QiitaForbiddenError ,
12
+ QiitaForbiddenOrBadRequestError ,
13
+ } from "../qiita-api" ;
10
14
11
15
export const publish = async ( argv : string [ ] ) => {
12
16
const args = arg (
@@ -117,6 +121,14 @@ export const publish = async (argv: string[]) => {
117
121
await fileSystemRepo . saveItem ( responseItem , false , true ) ;
118
122
} ) ;
119
123
120
- await Promise . all ( promises ) ;
124
+ try {
125
+ await Promise . all ( promises ) ;
126
+ } catch ( err ) {
127
+ if ( err instanceof QiitaForbiddenError ) {
128
+ // patchItem and postItem is possible to return 403 by bad request.
129
+ throw new QiitaForbiddenOrBadRequestError ( err . message , { cause : err } ) ;
130
+ }
131
+ throw err ;
132
+ }
121
133
console . log ( "Successful!" ) ;
122
134
} ;
Original file line number Diff line number Diff line change 2
2
QiitaBadRequestError ,
3
3
QiitaFetchError ,
4
4
QiitaForbiddenError ,
5
+ QiitaForbiddenOrBadRequestError ,
5
6
QiitaInternalServerError ,
6
7
QiitaNotFoundError ,
7
8
QiitaRateLimitError ,
@@ -44,6 +45,14 @@ export const handleError = async (error: Error) => {
44
45
) ;
45
46
console . error ( chalk . red ( "" ) ) ;
46
47
break ;
48
+ case QiitaForbiddenOrBadRequestError . name :
49
+ console . error ( chalk . red . bold ( "Qiita APIへのリクエストに失敗しました" ) ) ;
50
+ console . error ( chalk . red ( " 記事ファイルに不備がないかご確認ください" ) ) ;
51
+ console . error (
52
+ chalk . red ( " または、Qiitaのアクセストークンが正しいかご確認ください" ) ,
53
+ ) ;
54
+ console . error ( chalk . red ( "" ) ) ;
55
+ break ;
47
56
case QiitaNotFoundError . name :
48
57
console . error ( chalk . red . bold ( "記事が見つかりませんでした" ) ) ;
49
58
console . error (
Original file line number Diff line number Diff line change @@ -53,3 +53,11 @@ export class QiitaUnknownError extends Error {
53
53
this . name = "QiitaUnknownError" ;
54
54
}
55
55
}
56
+
57
+ export class QiitaForbiddenOrBadRequestError extends Error {
58
+ constructor ( message : string , options ?: { cause ?: Error } ) {
59
+ // @ts -expect-error This error is fixed in ES2022.
60
+ super ( message , options ) ;
61
+ this . name = "QiitaForbiddenOrBadRequestError" ;
62
+ }
63
+ }
You can’t perform that action at this time.
0 commit comments