GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-nodejs

Propagate framework errors to user application

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

Mô tả

Currently, errors that happen in the framework express layer are passed to the default express error handler. The default error handler returns the error to the client with a stack trace if in non-prod enviornments. It would be useful for certain cases for the user to have context of what happened during a request instead of the user being bypassed entirely. Instead, if the user has an error handler middleware installed in their application, we should pass the framework error to the user's error handler.

For example, if the framework gets a request with a bad json body.

```
const app = express():

app.post("/", (req, res) => {
...
});

// User error handler
app.use((err, req, res, next) => {
logger.log(err);
res.send("Caught error!");
});

functions.http("function, app);
```

```
// Post request with bad JSON
http.post("/", "{"id": "Hello}");
```

The framework responds with the following not very helpful message from the Express default error handler:

```
SyntaxError: Expected double-quoted property name in JSON at position 20 (line 3 column 1)
at JSON.parse ()
at parse (functions-framework-nodejs/node_modules/body-parser/lib/types/json.js:92:19)
at functions-framework-nodejs/node_modules/body-parser/lib/read.js:128:18
at AsyncResource.runInAsyncScope (node:async_hooks:211:14)
at invokeCallback (functions-framework-nodejs/node_modules/raw-body/index.js:238:16)
at done (functions-framework-nodejs/node_modules/raw-body/index.js:227:7)
at IncomingMessage.onEnd (functions-framework-nodejs/node_modules/raw-body/index.js:287:7)
at IncomingMessage.emit (node:events:518:28)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
```

There should be an option to propagate errors to the user client applcation, so their error handler is triggered and can preform logging, mitigations, or any other action the user wants instead of ignoring and leaving their application in the dust.

I've created #685 to address this issue.

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

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách lần theo cơ chế xử lý lỗi của Express-layer trong framework và xem xét issue liên quan #685. Thay đổi được hoàn tất khi các lỗi của framework, chẳng hạn như JSON không đúng định dạng, đi đến một user error-handler middleware đã được cài đặt, cho phép ứng dụng ghi log hoặc xử lý chúng thay vì Express handler mặc định phản hồi trực tiếp.

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

Đánh giá

Công nghệ
express, nodejs, typescript
Lĩnh vực
api, backend
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/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.