github.com/jfrog/jfrog-cli-platform-services@v1.2.0/commands/templates/BEFORE_DOWNLOAD.ts_template (about) 1 import { PlatformContext, BeforeDownloadRequest, BeforeDownloadResponse, DownloadStatus } from 'jfrog-workers'; 2 3 export default async (context: PlatformContext, data: BeforeDownloadRequest): Promise<BeforeDownloadResponse> => { 4 5 let status: DownloadStatus = DownloadStatus.DOWNLOAD_UNSPECIFIED; 6 7 try { 8 // The in-browser HTTP client facilitates making calls to the JFrog REST APIs 9 //To call an external endpoint, use 'await context.clients.axios.get("https://foo.com")' 10 const res = await context.clients.platformHttp.get('/artifactory/api/v1/system/readiness'); 11 12 // You should reach this part if the HTTP request status is successful (HTTP Status 399 or lower) 13 if (res.status === 200) { 14 status = DownloadStatus.DOWNLOAD_PROCEED; 15 console.log("Artifactory ping success"); 16 } else { 17 status = DownloadStatus.DOWNLOAD_WARN; 18 console.warn(`Request is successful but returned status other than 200. Status code : ${ res.status }`); 19 } 20 } catch(error) { 21 // The platformHttp client throws PlatformHttpClientError if the HTTP request status is 400 or higher 22 status = DownloadStatus.DOWNLOAD_STOP; 23 console.error(`Request failed with status code ${ error.status || '<none>' } caused by : ${ error.message }`) 24 } 25 26 return { 27 status, 28 message: 'Overwritten by worker-service if an error occurs.', 29 } 30 }