Fixed http exception error

This commit is contained in:
thomashii 2022-04-25 08:54:13 +08:00
parent 2ed19c08cc
commit 1717897b9a
29 changed files with 61 additions and 39 deletions

View file

@ -54,6 +54,7 @@ For more details, checkout [Project Status](https://github.com/dukefirehawk/ange
* Added default logger to generate standardised logging messages * Added default logger to generate standardised logging messages
* Added `melos` support * Added `melos` support
* Removed deprecated API * Removed deprecated API
* [**Breaking**] `error` for `AngelHttpException` is no longer mandatory
## Installation and Setup ## Installation and Setup

View file

@ -5,13 +5,10 @@
* Update examples * Update examples
* Update User Guide * Update User Guide
* Fix bugs * Fix bugs
* `angel3_oauth2` failed test cases
* `angel3_proxy` failed test cases
* `angel3_orm_mysql` * `angel3_orm_mysql`
## Long Term Goal ## Long Term Goal
* Refactor Angel3 architecture for performance and security * Refactor Angel3 architecture for performance and security
* Better logging for error messages
* Improve exception and error handling
* Improve ORM features * Improve ORM features
* Improve performances

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 6.0.1
* Fixed analyze error
## 6.0.0 ## 6.0.0
* Updated to SDK 2.16.x * Updated to SDK 2.16.x

View file

@ -41,7 +41,7 @@ class CorsOptions {
/// - `bool Function(String)` - set `origin` to a function implementing some custom logic. The function takes the request origin as the first parameter and returns a [bool]. /// - `bool Function(String)` - set `origin` to a function implementing some custom logic. The function takes the request origin as the first parameter and returns a [bool].
/// ///
/// Default: `'*'` /// Default: `'*'`
final origin; final dynamic origin;
/// If `false`, then the [cors] handler will terminate the response after performing its logic. /// If `false`, then the [cors] handler will terminate the response after performing its logic.
/// ///

View file

@ -1,5 +1,5 @@
name: angel3_cors name: angel3_cors
version: 6.0.0 version: 6.0.1
description: Angel3 CORS middleware. Ported from expressjs/cors to Angel3 framework. description: Angel3 CORS middleware. Ported from expressjs/cors to Angel3 framework.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/cors repository: https://github.com/dukefirehawk/angel/tree/master/packages/cors

View file

@ -1,10 +1,14 @@
# Change Log # Change Log
## 6.0.1
* Updated README
## 6.0.0 ## 6.0.0
* Updated to SDK 2.16.x * Updated to SDK 2.16.x
* Removed `error` * [**Breaking**] `error` for `AngelHttpException` is no longer mandatory
## 5.0.0 ## 5.0.0

View file

@ -12,7 +12,7 @@ class AngelHttpException implements Exception {
/// A list of errors that occurred when this exception was thrown. /// A list of errors that occurred when this exception was thrown.
final List<String> errors = []; final List<String> errors = [];
/// The cause of this exception. /// The error throw by exception.
dynamic error; dynamic error;
/// The cause of this exception. /// The cause of this exception.
@ -28,6 +28,7 @@ class AngelHttpException implements Exception {
{this.message = '500 Internal Server Error', {this.message = '500 Internal Server Error',
this.stackTrace, this.stackTrace,
this.statusCode = 500, this.statusCode = 500,
this.error,
List<String> errors = const []}) { List<String> errors = const []}) {
this.errors.addAll(errors); this.errors.addAll(errors);
} }

View file

@ -1,5 +1,5 @@
name: angel3_http_exception name: angel3_http_exception
version: 6.0.0 version: 6.0.1
description: Exception class that can be serialized to JSON and serialized to clients. description: Exception class that can be serialized to JSON and serialized to clients.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/http_exception repository: https://github.com/dukefirehawk/angel/tree/master/packages/http_exception

View file

@ -1 +1 @@
export 'src/server.dart'; export 'src/server.dart';

View file

@ -248,8 +248,7 @@ class CodeActionContext {
final List<Diagnostic>? diagnostics; final List<Diagnostic>? diagnostics;
Map toJson() => Map toJson() => {'diagnostics': diagnostics?.map((v) => v.toJson()).toList()};
{'diagnostics': diagnostics?.map((v) => v.toJson()).toList()};
@override @override
int get hashCode { int get hashCode {
var hash = 698635161; var hash = 698635161;
@ -966,10 +965,8 @@ class Diagnostics {
final String? uri; final String? uri;
Map toJson() => { Map toJson() =>
'diagnostics': diagnostics?.map((v) => v.toJson()).toList(), {'diagnostics': diagnostics?.map((v) => v.toJson()).toList(), 'uri': uri};
'uri': uri
};
@override @override
int get hashCode { int get hashCode {
var hash = 133599092; var hash = 133599092;
@ -2916,7 +2913,7 @@ int _deepHashCode(dynamic value) {
return (value.keys return (value.keys
.map((key) => _hashCombine(key.hashCode, _deepHashCode(value[key]))) .map((key) => _hashCombine(key.hashCode, _deepHashCode(value[key])))
.toList(growable: false) .toList(growable: false)
..sort()) ..sort())
.reduce(_hashCombine); .reduce(_hashCombine);
} }
return value.hashCode; return value.hashCode;

View file

@ -1,5 +1,10 @@
# Change Log # Change Log
## 6.0.1
* Fixed AngelHttpException error
* [Breaking] Renamed `error` to `authError` for `AuthorizationException`
## 6.0.0 ## 6.0.0
* Updated to SDK 2.16.x * Updated to SDK 2.16.x

View file

@ -5,9 +5,12 @@ class AuthorizationException extends AngelHttpException {
final ErrorResponse errorResponse; final ErrorResponse errorResponse;
AuthorizationException(this.errorResponse, AuthorizationException(this.errorResponse,
{StackTrace? stackTrace, int? statusCode, error}) {StackTrace? stackTrace, int? statusCode, dynamic error})
: super(error ?? errorResponse, : super(
stackTrace: stackTrace, message: '', statusCode: statusCode ?? 400); stackTrace: stackTrace,
message: '',
//error: error,
statusCode: statusCode ?? 400);
@override @override
Map toJson() { Map toJson() {

View file

@ -1,5 +1,5 @@
name: angel3_oauth2 name: angel3_oauth2
version: 6.0.0 version: 6.0.1
description: A class containing handlers that can be used within Angel to build a spec-compliant OAuth 2.0 server. description: A class containing handlers that can be used within Angel to build a spec-compliant OAuth 2.0 server.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/oauth2 repository: https://github.com/dukefirehawk/angel/tree/master/packages/oauth2

View file

@ -19,7 +19,7 @@ void main() {
setUp(() async { setUp(() async {
app = Angel(); app = Angel();
app.configuration['properties'] = app.configuration; app.configuration['properties'] = app.configuration;
app.container!.registerSingleton(AuthCodes()); app.container.registerSingleton(AuthCodes());
var server = _Server(); var server = _Server();

View file

@ -15,7 +15,7 @@ void main() {
setUp(() async { setUp(() async {
app = Angel(); app = Angel();
app.container!.registerSingleton(AuthCodes()); app.container.registerSingleton(AuthCodes());
var server = _Server(); var server = _Server();

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 6.0.1
* Fixed exception errors
## 6.0.0 ## 6.0.0
* Updated to SDK 2.16.x * Updated to SDK 2.16.x

View file

@ -116,7 +116,7 @@ class Proxy {
scheduleMicrotask(() => remote.pipe(local)); scheduleMicrotask(() => remote.pipe(local));
return false; return false;
} catch (e, st) { } catch (e, st) {
throw AngelHttpException(e, throw AngelHttpException(
message: 'Could not connect WebSocket', stackTrace: st); message: 'Could not connect WebSocket', stackTrace: st);
} }
} }
@ -167,7 +167,6 @@ class Proxy {
if (recoverFromDead) return true; if (recoverFromDead) return true;
throw AngelHttpException( throw AngelHttpException(
e,
stackTrace: st, stackTrace: st,
statusCode: 504, statusCode: 504,
message: message:
@ -189,7 +188,6 @@ class Proxy {
if (recoverFromDead) return true; if (recoverFromDead) return true;
throw AngelHttpException( throw AngelHttpException(
e,
stackTrace: st, stackTrace: st,
statusCode: 504, statusCode: 504,
message: 'Host "$uri" returned a malformed content-type', message: 'Host "$uri" returned a malformed content-type',

View file

@ -1,5 +1,5 @@
name: angel3_proxy name: angel3_proxy
version: 6.0.0 version: 6.0.1
description: Angel middleware to forward requests to another server (i.e. pub serve). description: Angel middleware to forward requests to another server (i.e. pub serve).
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/proxy repository: https://github.com/dukefirehawk/angel/tree/master/packages/proxy

View file

@ -12,7 +12,7 @@ Future<HttpServer> startTestServer() {
app.get('/foo/bar', (req, res) => res.write('baz')); app.get('/foo/bar', (req, res) => res.write('baz'));
app.post('/body', (RequestContext req, res) async { app.post('/body', (RequestContext req, res) async {
var body = await req.parseBody().then((_) => req.bodyAsMap); var body = await req.parseBody().then((_) => req.bodyAsMap);
app.logger!.info('Body: $body'); app.logger.info('Body: $body');
return body; return body;
}); });

View file

@ -2,7 +2,9 @@ import 'package:angel3_route/angel3_route.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
final router = Router()..get('/hello', '')..get('/user/:id', ''); final router = Router()
..get('/hello', '')
..get('/user/:id', '');
router.group('/book/:id', (router) { router.group('/book/:id', (router) {
router.get('/reviews', ''); router.get('/reviews', '');

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 6.0.1
* Fixed AngelHttpException error
## 6.0.0 ## 6.0.0
* Updated to SDK 2.16.x * Updated to SDK 2.16.x

View file

@ -38,7 +38,7 @@ void main() async {
// here we will use it to log invalid cookies. // here we will use it to log invalid cookies.
app.get('/cookies', (req, res) { app.get('/cookies', (req, res) {
var verifiedCookies = signer.readCookies(req, onInvalidCookie: (cookie) { var verifiedCookies = signer.readCookies(req, onInvalidCookie: (cookie) {
app.logger!.warning('Invalid cookie: $cookie'); app.logger.warning('Invalid cookie: $cookie');
}); });
res.writeln('${verifiedCookies.length} verified cookie(s)'); res.writeln('${verifiedCookies.length} verified cookie(s)');
res.writeln('${req.cookies.length} total unverified cookie(s)'); res.writeln('${req.cookies.length} total unverified cookie(s)');

View file

@ -85,7 +85,7 @@ abstract class RateLimiter<User> {
RateLimitingWindow<User> window, DateTime currentTime) { RateLimitingWindow<User> window, DateTime currentTime) {
var retryAfter = window.resetTime!.difference(currentTime); var retryAfter = window.resetTime!.difference(currentTime);
res.headers['retry-after'] = retryAfter.inSeconds.toString(); res.headers['retry-after'] = retryAfter.inSeconds.toString();
throw AngelHttpException(null, message: errorMessage, statusCode: 429); throw AngelHttpException(message: errorMessage, statusCode: 429);
} }
/// A request middleware that returns `true` if the user has not yet /// A request middleware that returns `true` if the user has not yet

View file

@ -1,5 +1,5 @@
name: angel3_security name: angel3_security
version: 6.0.0 version: 6.0.1
description: Angel3 infrastructure for improving security, rate limiting, and more description: Angel3 infrastructure for improving security, rate limiting, and more
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/security repository: https://github.com/dukefirehawk/angel/tree/master/packages/security

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 6.0.0-beta.2
* Fixed AngelHttpException error
## 6.0.0-beta.1 ## 6.0.0-beta.1
* Updated to SDK 2.16.x * Updated to SDK 2.16.x

View file

@ -48,7 +48,7 @@ Future<shelf.Request> convertRequest(RequestContext req, ResponseContext res,
hijack(ctrl.foreign); hijack(ctrl.foreign);
} catch (e, st) { } catch (e, st) {
app?.logger app?.logger
?.severe('An error occurred while hijacking a shelf request', e, st); .severe('An error occurred while hijacking a shelf request', e, st);
} }
}; };

View file

@ -19,9 +19,8 @@ RequestHandler embedShelf(shelf.Handler handler,
handlerPath: handlerPath, context: context); handlerPath: handlerPath, context: context);
try { try {
var result = await handler(shelfRequest); var result = await handler(shelfRequest);
if (result is! shelf.Response) return result;
if (throwOnNullResponse == true) { if (throwOnNullResponse == true) {
throw AngelHttpException('Internal Server Error'); throw AngelHttpException(message: 'Internal Server Error');
} }
await mergeShelfResponse(result, res); await mergeShelfResponse(result, res);
return false; return false;

View file

@ -6,9 +6,8 @@ import 'package:shelf/shelf.dart';
import 'shelf_request.dart'; import 'shelf_request.dart';
import 'shelf_response.dart'; import 'shelf_response.dart';
// TODO: To be reviewed
Future<Stream<Request>> process(dynamic param1, int param2) { Future<Stream<Request>> process(dynamic param1, int param2) {
return Future.value(); return Future.value(Stream.empty());
} }
class AngelShelf extends Driver<shelf.Request, ShelfResponseContext?, class AngelShelf extends Driver<shelf.Request, ShelfResponseContext?,
@ -106,7 +105,7 @@ class AngelShelf extends Driver<shelf.Request, ShelfResponseContext?,
var path = request.url.path.replaceAll(_straySlashes, ''); var path = request.url.path.replaceAll(_straySlashes, '');
if (path.isEmpty) path = '/'; if (path.isEmpty) path = '/';
var rq = var rq =
ShelfRequestContext(app, app.container!.createChild(), request, path); ShelfRequestContext(app, app.container.createChild(), request, path);
return Future.value(rq); return Future.value(rq);
} }

View file

@ -1,5 +1,5 @@
name: angel3_shelf name: angel3_shelf
version: 6.0.0-beta.1 version: 6.0.0-beta.2
description: Shelf interop with Angel3. Use this to wrap existing server code. description: Shelf interop with Angel3. Use this to wrap existing server code.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/shelf repository: https://github.com/dukefirehawk/angel/tree/master/packages/shelf