Result Aggregator
Parse trigger payload to JSON and write to the session storage.
Logic type | Input | Output |
---|---|---|
Aggregator | Session variable result (type: any , optional) | None |
note
The logic will finalise and return the error if any occurred in the task, but it would not be able to indicate where it had occurred. You can pass additional session data in other logic to include the context metadata.
- JavaScript
- JavaScript (with JSDoc)
- TypeScript
result-aggregator.js
import {
ResultAgent,
LoggingAgent,
SessionStorageAgent,
} from "@fstnetwork/loc-logic-sdk";
export async function run(ctx) {
// read result from session
const result = await SessionStorageAgent.get("result");
// logging
LoggingAgent.info({ result: result });
// finalise result
ResultAgent.finalize({
status: "ok",
taskKey: ctx.task.taskKey,
data: result,
});
}
export async function handleError(ctx, error) {
const err = {
error: true,
errorMessage: error.message,
stack: error.stack,
taskKey: ctx.task.taskKey,
};
// error logging
LoggingAgent.error(err);
// finalise result
ResultAgent.finalize(err).httpStatusCode(500);
}
result-aggregator.js
import {
ResultAgent,
LoggingAgent,
SessionStorageAgent,
} from "@fstnetwork/loc-logic-sdk";
/** @param {import('@fstnetwork/loc-logic-sdk').AggregatorContext} ctx */
export async function run(ctx) {
// read result from session
/** @type { any } */
const result = await SessionStorageAgent.get("result");
// logging
LoggingAgent.info({ result: result });
// finalise result
ResultAgent.finalize({
status: "ok",
taskKey: ctx.task.taskKey,
data: result,
});
}
/**
* @param {import('@fstnetwork/loc-logic-sdk').AggregatorContext} ctx
* @param {import('@fstnetwork/loc-logic-sdk').RailwayError} error
*/
export async function handleError(ctx, error) {
const err = {
error: true,
errorMessage: error.message,
stack: error.stack,
taskKey: ctx.task.taskKey,
};
// error logging
LoggingAgent.error(err);
// finalise result
ResultAgent.finalize(err).httpStatusCode(500);
}
result-aggregator.ts
import {
AggregatorContext,
RailwayError,
ResultAgent,
LoggingAgent,
SessionStorageAgent,
} from "@fstnetwork/loc-logic-sdk";
export async function run(ctx: AggregatorContext) {
// read result from session
const result = (await SessionStorageAgent.get("result")) as any;
// logging
LoggingAgent.info({ result: result });
// finalise result
ResultAgent.finalize({
status: "ok",
taskKey: ctx.task.taskKey,
data: result,
});
}
export async function handleError(ctx: AggregatorContext, error: RailwayError) {
const err = {
error: true,
errorMessage: error.message,
stack: error.stack,
taskKey: ctx.task.taskKey,
};
// error logging
LoggingAgent.error(err);
// finalise result
ResultAgent.finalize(err).httpStatusCode(500);
}