From fc5df85b9ba363c3d5185e8fa1c1d40b9b7d88ac Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 10 Feb 2019 19:18:12 -0500 Subject: [PATCH] 1.1.0 --- CHANGELOG.md | 4 ++++ analysis_options.yaml | 1 + lib/angel_http_exception.dart | 39 ++++++++++++++++++++--------------- pubspec.yaml | 8 ++++--- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0106511a..07005955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.1.0 +* Emit `is_error` and `status_code` in `toJson()`. + * No more `camelCase` at all. + # 1.0.0+3 * Slightly relax the deserialization of `errors`. diff --git a/analysis_options.yaml b/analysis_options.yaml index eae1e42a..c230cee7 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1,4 @@ +include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false \ No newline at end of file diff --git a/lib/angel_http_exception.dart b/lib/angel_http_exception.dart index 3900206f..cac6145f 100644 --- a/lib/angel_http_exception.dart +++ b/lib/angel_http_exception.dart @@ -2,7 +2,10 @@ library angel_http_exception; import 'package:dart2_constant/convert.dart'; -/// Basically the same as +/// Exception class that can be serialized to JSON and serialized to clients. +/// Carries HTTP-specific metadata, like [statusCode]. +/// +/// Originally inspired by /// [feathers-errors](https://github.com/feathersjs/feathers-errors). class AngelHttpException implements Exception { var error; @@ -20,10 +23,10 @@ class AngelHttpException implements Exception { int statusCode; AngelHttpException(this.error, - {this.message: '500 Internal Server Error', + {this.message = '500 Internal Server Error', this.stackTrace, - this.statusCode: 500, - List errors: const []}) { + this.statusCode = 500, + List errors = const []}) { if (errors != null) { this.errors.addAll(errors); } @@ -31,7 +34,7 @@ class AngelHttpException implements Exception { Map toJson() { return { - 'isError': true, + 'is_error': true, 'status_code': statusCode, 'message': message, 'errors': errors @@ -62,57 +65,59 @@ class AngelHttpException implements Exception { /// Throws a 400 Bad Request error, including an optional arrray of (validation?) /// errors you specify. factory AngelHttpException.badRequest( - {String message: '400 Bad Request', List errors: const []}) => + {String message = '400 Bad Request', + List errors = const []}) => new AngelHttpException(null, message: message, errors: errors, statusCode: 400); /// Throws a 401 Not Authenticated error. factory AngelHttpException.notAuthenticated( - {String message: '401 Not Authenticated'}) => + {String message = '401 Not Authenticated'}) => new AngelHttpException(null, message: message, statusCode: 401); /// Throws a 402 Payment Required error. factory AngelHttpException.paymentRequired( - {String message: '402 Payment Required'}) => + {String message = '402 Payment Required'}) => new AngelHttpException(null, message: message, statusCode: 402); /// Throws a 403 Forbidden error. - factory AngelHttpException.forbidden({String message: '403 Forbidden'}) => + factory AngelHttpException.forbidden({String message = '403 Forbidden'}) => new AngelHttpException(null, message: message, statusCode: 403); /// Throws a 404 Not Found error. - factory AngelHttpException.notFound({String message: '404 Not Found'}) => + factory AngelHttpException.notFound({String message = '404 Not Found'}) => new AngelHttpException(null, message: message, statusCode: 404); /// Throws a 405 Method Not Allowed error. factory AngelHttpException.methodNotAllowed( - {String message: '405 Method Not Allowed'}) => + {String message = '405 Method Not Allowed'}) => new AngelHttpException(null, message: message, statusCode: 405); /// Throws a 406 Not Acceptable error. factory AngelHttpException.notAcceptable( - {String message: '406 Not Acceptable'}) => + {String message = '406 Not Acceptable'}) => new AngelHttpException(null, message: message, statusCode: 406); /// Throws a 408 Timeout error. - factory AngelHttpException.methodTimeout({String message: '408 Timeout'}) => + factory AngelHttpException.methodTimeout({String message = '408 Timeout'}) => new AngelHttpException(null, message: message, statusCode: 408); /// Throws a 409 Conflict error. - factory AngelHttpException.conflict({String message: '409 Conflict'}) => + factory AngelHttpException.conflict({String message = '409 Conflict'}) => new AngelHttpException(null, message: message, statusCode: 409); /// Throws a 422 Not Processable error. factory AngelHttpException.notProcessable( - {String message: '422 Not Processable'}) => + {String message = '422 Not Processable'}) => new AngelHttpException(null, message: message, statusCode: 422); /// Throws a 501 Not Implemented error. factory AngelHttpException.notImplemented( - {String message: '501 Not Implemented'}) => + {String message = '501 Not Implemented'}) => new AngelHttpException(null, message: message, statusCode: 501); /// Throws a 503 Unavailable error. - factory AngelHttpException.unavailable({String message: '503 Unavailable'}) => + factory AngelHttpException.unavailable( + {String message = '503 Unavailable'}) => new AngelHttpException(null, message: message, statusCode: 503); } diff --git a/pubspec.yaml b/pubspec.yaml index a8a96bab..6853dd48 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,9 +1,11 @@ name: angel_http_exception -version: 1.0.0+3 -description: Angel's HTTP exception class. +version: 1.1.0 +description: Exception class that can be serialized to JSON and serialized to clients. author: Tobe O homepage: https://github.com/angel-dart/http_exception environment: sdk: ">=1.19.0 <3.0.0" dependencies: - dart2_constant: ^1.0.0 \ No newline at end of file + dart2_constant: ^1.0.0 +dev_dependencies: + pedantic: ^1.0.0 \ No newline at end of file