Skip to content

Commit eba1632

Browse files
committed
error handling
1 parent b228ce6 commit eba1632

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

files/move/action.yml

+14-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,20 @@ runs:
4040
// Get Dropbox access token
4141
const accessTokenResponse = execSync(`curl -s https://api.dropbox.com/oauth2/token -d refresh_token=${DROPBOX_REFRESH_TOKEN} -d grant_type=refresh_token -d client_id=${DROPBOX_APP_KEY} -d client_secret=${DROPBOX_APP_SECRET}`).toString();
4242
const accessToken = JSON.parse(accessTokenResponse).access_token;
43-
44-
// Move the file/folder on Dropbox
45-
const output = execSync(`curl -X POST https://api.dropboxapi.com/2/files/move_v2 -H 'Authorization: Bearer ${accessToken}' -H 'Content-Type: application/json' -d '{"from_path": "${SOURCE_PATH}", "to_path": "${DEST_PATH}"}'`);
46-
console.log('output:', output.toString());
47-
//execSync(`curl -X POST https://api.dropboxapi.com/2/files/move_v2 --header "Authorization: Bearer ${accessToken}" --header "Dropbox-API-Arg: {\\"from_path\\": \\"${SOURCE_PATH}\\",\\"to_path\\": \\"${DEST_PATH}\\"}"`);
43+
try {
44+
// Move the file/folder on Dropbox
45+
const output = execSync(`curl -X POST https://api.dropboxapi.com/2/files/move_v2 -H 'Authorization: Bearer ${accessToken}' -H 'Content-Type: application/json' -d '{"from_path": "${SOURCE_PATH}", "to_path": "${DEST_PATH}"}'`);
46+
47+
const parsedResponse = JSON.parse(output.toString());
48+
49+
if (parsedResponse.error_summary || parsedResponse.error) {
50+
throw new Error(parsedResponse.error_summary || parsedResponse.error);
51+
} else {
52+
console.log(`${SOURCE_PATH} moved to ${DEST_PATH} successfully`);
53+
}
54+
} catch (error) {
55+
throw new Error(error.message);
56+
}
4857
env:
4958
DROPBOX_APP_KEY: ${{ inputs.DROPBOX_APP_KEY }}
5059
DROPBOX_APP_SECRET: ${{ inputs.DROPBOX_APP_SECRET }}

0 commit comments

Comments
 (0)