* Extracts module name from route path * Examples: /users/123 → 'user-service', /payments → 'payment-service'
(routePath: string)
| 19 | const resource = match[1] |
| 20 | const singular = pluralExceptions[resource] ?? resource.replace(/s$/, '') |
| 21 | return `${singular}-service` |
| 22 | } |
| 23 | |
| 24 | const errorHandler: FastifyPluginAsync = async fastify => { |
| 25 | fastify.setErrorHandler((error: FastifyError, request, reply) => { |
| 26 | const routePath: string = |
| 27 | 'routerPath' in request && typeof request.routerPath === 'string' |
| 28 | ? request.routerPath |
| 29 | : (request.url.split('?')[0] ?? '/') |
| 30 | |
| 31 | const module = extractModuleFromRoute(routePath) ?? 'api-route' |
| 32 | const statusCode: number = |