47ng / 47ng/fastify-micro

RFC-7807 for errors

Abierto
#415 0 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
TypeScript
Estrellas
46
Forks
4
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

In combination with `fastify.sensible`, make it easy to send well-formatted errors to clients, with actionable details for better DX.

Specification: https://tools.ietf.org/html/rfc7807

Copy-pasta from another project:
```ts
// https://tools.ietf.org/html/rfc7807

import { STATUS_CODES } from 'node:http'
import { z } from 'zod'

export const rfc7807Schema = z.object({
status: z
.number()
.int()
.refine(code => code in STATUS_CODES),
type: z.string().url().optional(), // Technically a URI, but let's not split hairs
title: z.string(),
detail: z.string().optional(),
instance: z.string().url().optional()
})

export type RFC7807 = z.TypeOf

export class RFC7807Error extends Error {
readonly rfc7807: RFC7807

constructor(args: RFC7807) {
super(
`${STATUS_CODES[args.status]}: ${args.title}${
args.detail ? ` (${args.detail})` : ''
}`
)
this.name = 'RFC7807Error'
this.rfc7807 = {
...args,
type: args.type ?? 'about:blank'
}
}
}
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Look at the existing error handling in fastify-micro, likely in a plugin or middleware. Integrate the provided RFC7807 schema and error class, ensuring compatibility with fastify.sensible. Test by creating errors and verifying the response format matches the RFC.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
nodejs, typescript
Área
api, backend
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.