@@ -217,12 +217,12 @@ function getTargetFile(targetPath, source) {
217217}
218218
219219async function uploadFile ( serverId , targetFile , buffer ) {
220- // check if the response was 403 (forbidden), try again until the max retries is reached
221220 let retries = 0 ;
222221 let uploaded = false ;
222+
223223 while ( ! uploaded && retries < 3 ) {
224224 try {
225- response = await axios . post (
225+ const response = await axios . post (
226226 `/api/client/servers/${ serverId } /files/write` ,
227227 buffer ,
228228 {
@@ -237,18 +237,31 @@ async function uploadFile(serverId, targetFile, buffer) {
237237 } ,
238238 }
239239 ) ;
240- if ( response ?. status == 204 || response ?. status == 200 ) {
240+
241+ // API returns 200 on successful upload
242+ if ( response . status === 200 || response . status === 204 ) {
243+ core . info ( `Successfully uploaded ${ targetFile } to ${ serverId } ` ) ;
241244 uploaded = true ;
242245 } else {
243- core . error (
244- `Upload failed with status ${ response ? .status } , retrying...`
246+ core . warning (
247+ `Upload returned unexpected status ${ response . status } , retrying...`
245248 ) ;
249+ retries ++ ;
246250 }
247251 } catch ( error ) {
248- core . error ( `Upload failed with error ${ error } , retrying...` ) ;
252+ retries ++ ;
253+ if ( retries >= 3 ) {
254+ throw new Error ( `Failed to upload ${ targetFile } after ${ retries } attempts: ${ error . message } ` ) ;
255+ }
256+ core . warning ( `Upload attempt ${ retries } failed, retrying...` ) ;
249257 core . debug ( `Error response: ${ JSON . stringify ( error ?. response ?. data ) } ` ) ;
258+ // Wait a bit before retrying
259+ await new Promise ( resolve => setTimeout ( resolve , 1000 * retries ) ) ;
250260 }
251- retries ++ ;
261+ }
262+
263+ if ( ! uploaded ) {
264+ throw new Error ( `Failed to upload ${ targetFile } after ${ retries } attempts` ) ;
252265 }
253266}
254267
0 commit comments