GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-nodejs
Propagate framework errors to user application
- 主要言語
- TypeScript
- スター
- 1.4k
- フォーク
- 181
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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.
コントリビューションガイド
調査の方向性
まず、framework の Express-layer の error handling を追跡し、関連する issue #685 を確認してください。framework のエラー(malformed JSON など)が、インストールされた user error-handler middleware に到達し、デフォルトの Express handler が直接応答するのではなく、アプリケーションでログに記録したり処理したりできるようになれば、変更は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- express, nodejs, typescript
- 領域
- api, backend
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100