dart-backend / angel

A polished, production-ready backend framework in Dart for the VM, AOT, and Flutter.
https://github.com/dukefirehawk/angel
BSD 3-Clause "New" or "Revised" License
171 stars 22 forks source link

fix: res.json() will cause 'Bad state: Cannot modify a closed respons… #15

Closed debuggerx01 closed 2 years ago

debuggerx01 commented 2 years ago

When I writen a simple api like this:

Future configureServer(Angel app) async {
  app.get('/test', (req, res) => res.json({"test": "ok"}));
}

I got this error:

[SEVERE] service_proxy: Bad state: Cannot modify a closed response.

Bad state: Cannot modify a closed response.
package:angel3_framework/src/core/response_context.dart 309:7  ResponseContext.serialize
package:angel3_framework/src/core/server.dart 280:20           Angel.executeHandler.<fn>
dart:async                                                     _CustomZone.runUnary
package:angel3_framework/src/core/driver.dart 414:22           Driver.runPipeline
package:angel3_hot/angel3_hot.dart 119:14                      HotReloader.handleRequest

I think it was caused by the json() should not return the type of ResponseContext. In addition, in serialize(value, {MediaType? contentType}), this.contentType will set to optional param contentType, so I think the code of ..contentType = MediaType('application', 'json') in json() is unavailing.

dukefirehawk commented 2 years ago

Good fix