-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): in backup CLI, add common action to extract error from API …
…response, use yargs to parse CLI flags
- Loading branch information
Showing
15 changed files
with
123 additions
and
78 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
packages/sanity/src/_internal/cli/actions/backup/archiveDir.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/sanity/src/_internal/cli/actions/backup/chooseBackupIdPrompt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/sanity/src/_internal/cli/actions/backup/cleanupTmpDir.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import rimraf from 'rimraf' | ||
|
||
import debug from './debug' | ||
|
||
function cleanupTmpDir(tmpDir: string): void { | ||
|
6 changes: 4 additions & 2 deletions
6
packages/sanity/src/_internal/cli/actions/backup/downloadAsset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/sanity/src/_internal/cli/actions/backup/downloadDocument.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/sanity/src/_internal/cli/actions/backup/fetchNextBackupPage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/sanity/src/_internal/cli/actions/backup/parseApiErr.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// apiErr is a type that represents an error returned by the API | ||
interface ApiErr { | ||
statusCode: number | ||
message: string | ||
} | ||
|
||
// parseApiErr is a function that attempts with the best effort to parse | ||
// an error returned by the API since different API endpoint may end up | ||
// returning different error structures. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types | ||
function parseApiErr(err: any): ApiErr { | ||
const apiErr = {} as ApiErr | ||
if (err.code) { | ||
apiErr.statusCode = err.code | ||
} else if (err.statusCode) { | ||
apiErr.statusCode = err.statusCode | ||
} | ||
|
||
if (err.message) { | ||
apiErr.message = err.message | ||
} else if (err.statusMessage) { | ||
apiErr.message = err.statusMessage | ||
} else if (err?.response?.body?.message) { | ||
apiErr.message = err.response.body.message | ||
} else if (err?.response?.data?.message) { | ||
apiErr.message = err.response.data.message | ||
} else { | ||
// If no message can be extracted, print the whole error. | ||
apiErr.message = JSON.stringify(err) | ||
} | ||
|
||
return apiErr | ||
} | ||
|
||
export default parseApiErr |
2 changes: 1 addition & 1 deletion
2
packages/sanity/src/_internal/cli/actions/backup/progressSpinner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
packages/sanity/src/_internal/cli/actions/backup/resolveApiClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/sanity/src/_internal/cli/commands/backup/disableBackupCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/sanity/src/_internal/cli/commands/backup/enableBackupCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function isPathDirName(filepath: string): boolean { | ||
// Check if the path has an extension, commonly indicating a file | ||
return !/\.\w+$/.test(filepath) | ||
} | ||
|
||
export default isPathDirName |