@parser({ envelope:SqsEnvelope, schema:OrderSchema }) publicasynchandler(event: Order, _context: Context): Promise<unknown> { // sqs event is parsed and the payload is extracted and parsed // apply business logic to your Order event constres = processOrder(event); returnres; } }
In case you want to parse the event and handle the error, you can use the safeParse option.
The safeParse option will return an object with the parsed event and an error object if the parsing fails.
@parser({ envelope:SqsEnvelope, schema:OrderSchema, safeParse:true }) publicasynchandler(event: ParsedResult<Order>, _context: unknown): Promise<unknown> { if (event.success) { // event.data is the parsed event object of type Order } else { // event.error is the error object, you can inspect and recover // event.originalEvent is the original event that failed to parse } } }
A decorator to parse your event.
Example
In case you want to parse the event and handle the error, you can use the safeParse option. The safeParse option will return an object with the parsed event and an error object if the parsing fails.
Example