Closed ngoctienle closed 2 months ago
@ngoctienle Hiện tại đã có sẵn x-request-id tương tự trace_id rồi đó em. Nó có sẵn khi tích hợp pino-logger https://github.com/vndevteam/nestjs-boilerplate/blob/develop/src/utils/logger-factory.ts#L103
@ngoctienle Về phần failed response thì đã có define ở error.dto.ts rồi nè em
Còn Ok response thì anh đang không hướng theo kiểu
data: []
do thấy hơi rườm rà
Không biết ý em có phải vậy không?
Dạ vâng, thường thì em thấy
@ngoctienle Về phần failed response thì đã có define ở error.dto.ts rồi nè em
Còn Ok response thì anh đang không hướng theo kiểu
data: []
do thấy hơi rườm rà
Không biết ý em có phải vậy không?
@khuongln-1346 Dạ vâng, thường thì em thấy các dự án hay có structure response riêng kiểu kiểu như này, và Error cũng thế
interface OkResponse<T> {
success: true
data: T
message: string
}
@ngoctienle Cái này chỉ là optional thôi em, nhiều team họ sẽ thấy rườm rà mà bỏ đi, nhiều team thì lại muốn quy chuẩn
Anh cũng từng code theo kiểu này trong một số dự án rồi, và thấy nó bất tiện + thừa
Vì phần này implement không khó, nên nếu muốn implement thêm ở các project thì ae tự thêm em nhé. Boilerplate này mình giữ common một tý
@lamngockhuong Thanks anh đã giải đáp, em hiểu rồi ạ.
Hi anh, em thấy hiện tại source mình chưa có custom cho response. Kiểu hiện tại em thấy các dự án lớn có một structure response cho Ok riêng, Error riêng để phía client có thể define đc Interface từ đầu.
Ngoài ra, việc bổ sung thêm Tracing (trace_id) ở request header và response, Logger là điều cần thiết.
https://medium.com/@alexanderknips/open-telemetry-with-multiple-nestjs-and-logs-in-tracing-62453e3e6cb2