47ng / 47ng/fastify-micro

RFC-7807 for errors

Đang mở
#415 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
TypeScript
Star
46
Fork
4
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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'
}
}
}
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
nodejs, typescript
Lĩnh vực
api, backend
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.