The following section provides a sample code for an After Download Error worker.
export default async (
context: PlatformContext,
data: AfterDownloadErrorRequest
): Promise<AfterDownloadErrorResponse> => {
try {
// The in-browser HTTP client facilitates making calls to the JFrog REST APIs
//To call an external endpoint, use 'await context.clients.axios.get("https://foo.com")'
const res = await context.clients.platformHttp.get(
"/artifactory/api/v1/system/readiness"
);
// You should reach this part if the HTTP request status is successful (HTTP Status 399 or lower)
if (res.status === 200) {
console.log("Artifactory ping success");
} else {
console.warn(
`Request is successful but returned status other than 200. Status code : ${res.status}`
);
}
} catch (error) {
// The platformHttp client throws PlatformHttpClientError if the HTTP request status is 400 or higher
console.error(
`Request failed with status code ${
error.status || "<none>"
} caused by : ${error.message}`
);
}
return {
message: "proceed",
};
};
Input Parameters
context
Provides baseUrl, token, and clients to communicate with the JFrog Platform (for more information, see PlatformContext).
data
The request with download request details sent by Artifactory.
{
"metadata": { // Object containing metadata information about the artifact
"repoPath": { // Information about the current repository path for the artifact
"key": "local-repo", // Unique identifier for the repository
"path": "folder/subfolder/my-file", // Current path to the specific file within the repository
"id": "local-repo:folder/subfolder/my-file", // Unique identifier combining the repo key and path
"isRoot": false, // Indicates if the path is a root directory (false means it is not)
"isFolder": false // Indicates if the path is a folder (false means it is a file)
},
"originalRepoPath": { // Information about the original repository path before any changes
"key": "local-repo", // Unique identifier for the original repository
"path": "old/folder/subfolder/my-file", // Previous path to the file before modification
"id": "local-repo:old/folder/subfolder/my-file", // Unique identifier for the original path
"isRoot": false, // Indicates if the original path is a root directory (false means it is not)
"isFolder": false // Indicates if the original path is a folder (false means it is a file)
},
"name": "my-file", // Name of the file
"headOnly": false, // Indicates if only the header request is to be processed
"checksum": false, // Indicates whether to calculate a checksum for the file
"recursive": false, // Indicates if the operation should be recursive (false means it is not)
"modificationTime": 0, // Time of last modification (0 indicates no modification)
"directoryRequest": false, // Indicates if the request is for a directory
"metadata": false, // Indicates if metadata should be included in the request
"lastModified": 1, // Timestamp of the last modification (assuming it is Unix timestamp)
"ifModifiedSince": 0, // Timestamp to check if the file has been modified since this time (0 indicates no check)
"servletContextUrl": "https://jpd.jfrog.io/artifactory", // URL for the servlet context accessing the artifact
"uri": "/artifactory/local-repo/folder/subfolder/my-file", // URI for accessing the artifact
"clientAddress": "100.100.100.100", // IP address of the client making the request
"zipResourcePath": "", // Path to zip resource if applicable (empty indicates none)
"zipResourceRequest": false, // Indicates if the request involves a zip resource
"replaceHeadRequestWithGet": false, // Indicates if HEAD requests should be replaced with GET requests
"repoType": 1 // Numeric identifier representing the repository type (e.g., local, remote, virtual)
},
"userContext": { // Object containing context information about the user making the request
"id": "jffe@00xxxxxxxxxxxxxxxxxxxxxxxx/users/bob", // Unique identifier for the user
"isToken": true, // Indicates if the user is authenticated via a token
"realm": "realm" // Realm for user authentication context
},
"requestHeaders": { // HTTP headers associated with the request
"Content-Type": { // Content-Type header for the request
"value": [ // Array of values for the Content-Type header
"text/plain" // Indicates that the content type is plain text
]
},
"Accept": { // Accept header for the request
"value": [ // Array of values for the Accept header
"application/json" // Indicates that the expected response format is JSON
]
}
}
{
Response
{
"message": "proceed" // Message to print to the log, in case of an error, it will be printed as a warning
}
message : This is a mandatory field.