File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Expand file tree Collapse file tree 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";
66import { getQiitaApiInstance } from "../lib/get-qiita-api-instance" ;
77import { syncArticlesFromQiita } from "../lib/sync-articles-from-qiita" ;
88import { validateItem } from "../lib/validators/item-validator" ;
9- import { Item } from "../qiita-api" ;
9+ import {
10+ Item ,
11+ QiitaForbiddenError ,
12+ QiitaForbiddenOrBadRequestError ,
13+ } from "../qiita-api" ;
1014
1115export const publish = async ( argv : string [ ] ) => {
1216 const args = arg (
@@ -117,6 +121,14 @@ export const publish = async (argv: string[]) => {
117121 await fileSystemRepo . saveItem ( responseItem , false , true ) ;
118122 } ) ;
119123
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+ }
121133 console . log ( "Successful!" ) ;
122134} ;
Original file line number Diff line number Diff line change 22 QiitaBadRequestError ,
33 QiitaFetchError ,
44 QiitaForbiddenError ,
5+ QiitaForbiddenOrBadRequestError ,
56 QiitaInternalServerError ,
67 QiitaNotFoundError ,
78 QiitaRateLimitError ,
@@ -44,6 +45,14 @@ export const handleError = async (error: Error) => {
4445 ) ;
4546 console . error ( chalk . red ( "" ) ) ;
4647 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 ;
4756 case QiitaNotFoundError . name :
4857 console . error ( chalk . red . bold ( "記事が見つかりませんでした" ) ) ;
4958 console . error (
Original file line number Diff line number Diff line change @@ -53,3 +53,11 @@ export class QiitaUnknownError extends Error {
5353 this . name = "QiitaUnknownError" ;
5454 }
5555}
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