2 min read
Dispatch table
Map each type to a handler; fall through to a no-op.
const handlers = {
'enquiry.created': onEnquiryCreated,
'decision.completed': onDecisionCompleted,
'payment.failed': onPaymentFailed,
};
function dispatch(evt) {
(handlers[evt.type] || (() => {}))(evt.data.object);
}
Ignore unknown types
New types are added additively (see the catalogue). Never throw on an unrecognised type — that turns a harmless new event into a delivery failure and a retry storm.
Keep handlers idempotent
Each handler still runs behind the idempotency guard keyed on the event id.
Frequently asked questions
Should I 500 on an unknown type?
No — return 200 and ignore it. A 500 triggers retries for an event you were never going to handle anyway.
One endpoint or many?
One is simpler: register a single endpoint subscribed to the types you handle and dispatch internally. Multiple endpoints only help if different teams own different events.
How do I keep the dispatch table maintainable?
Keep each handler small and single-purpose, and name them after the event type they serve. When a new type from the catalogue becomes relevant, you add one entry — the fall-through no-op means you never have to touch the ones you do not care about.
Funding for UK limited companies
Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.