feat: Add logging to API Post component for better debugging

This commit is contained in:
Simon Larsen 2024-10-01 19:17:15 +01:00
parent cc0670c291
commit 84fcb265f6
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA

View File

@ -11,6 +11,7 @@ import ComponentMetadata, { Port } from "Common/Types/Workflow/Component";
import ComponentID from "Common/Types/Workflow/ComponentID";
import APIComponents from "Common/Types/Workflow/Components/API";
import API from "Common/Utils/API";
import logger from "../../../../Utils/Logger";
export default class ApiPost extends ComponentCode {
public constructor() {
@ -38,6 +39,25 @@ export default class ApiPost extends ComponentCode {
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null = null;
logger.debug("API Post Component is running.");
const url: URL = args["url"] as URL;
if (!url) {
throw options.onError(new BadDataException("URL is required"));
}
logger.debug(`URL: ${url}`);
const requestBody: JSONObject = args["request-body"] as JSONObject;
logger.debug(`Request Body: ${JSON.stringify(requestBody)}`);
const requestHeaders: Dictionary<string> = args[
"request-headers"
] as Dictionary<string>;
logger.debug(`Request Headers: ${JSON.stringify(requestHeaders)}`);
try {
apiResult = await API.post(
args["url"] as URL,
@ -45,6 +65,8 @@ export default class ApiPost extends ComponentCode {
args["request-headers"] as Dictionary<string>,
);
logger.debug("API Post Component is done.");
return Promise.resolve({
returnValues: ApiComponentUtils.getReturnValues(apiResult),
executePort: result.successPort,
@ -64,6 +86,9 @@ export default class ApiPost extends ComponentCode {
});
}
logger.debug("API Post Component is done with error.");
logger.debug(err);
throw options.onError(new APIException("Something wrong happened."));
}
}