1.1.0
This commit is contained in:
parent
c025992f47
commit
fc5df85b9b
4 changed files with 32 additions and 20 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
# 1.1.0
|
||||||
|
* Emit `is_error` and `status_code` in `toJson()`.
|
||||||
|
* No more `camelCase` at all.
|
||||||
|
|
||||||
# 1.0.0+3
|
# 1.0.0+3
|
||||||
* Slightly relax the deserialization of `errors`.
|
* Slightly relax the deserialization of `errors`.
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
include: package:pedantic/analysis_options.yaml
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode:
|
strong-mode:
|
||||||
implicit-casts: false
|
implicit-casts: false
|
|
@ -2,7 +2,10 @@ library angel_http_exception;
|
||||||
|
|
||||||
import 'package:dart2_constant/convert.dart';
|
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).
|
/// [feathers-errors](https://github.com/feathersjs/feathers-errors).
|
||||||
class AngelHttpException implements Exception {
|
class AngelHttpException implements Exception {
|
||||||
var error;
|
var error;
|
||||||
|
@ -20,10 +23,10 @@ class AngelHttpException implements Exception {
|
||||||
int statusCode;
|
int statusCode;
|
||||||
|
|
||||||
AngelHttpException(this.error,
|
AngelHttpException(this.error,
|
||||||
{this.message: '500 Internal Server Error',
|
{this.message = '500 Internal Server Error',
|
||||||
this.stackTrace,
|
this.stackTrace,
|
||||||
this.statusCode: 500,
|
this.statusCode = 500,
|
||||||
List<String> errors: const []}) {
|
List<String> errors = const []}) {
|
||||||
if (errors != null) {
|
if (errors != null) {
|
||||||
this.errors.addAll(errors);
|
this.errors.addAll(errors);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +34,7 @@ class AngelHttpException implements Exception {
|
||||||
|
|
||||||
Map toJson() {
|
Map toJson() {
|
||||||
return {
|
return {
|
||||||
'isError': true,
|
'is_error': true,
|
||||||
'status_code': statusCode,
|
'status_code': statusCode,
|
||||||
'message': message,
|
'message': message,
|
||||||
'errors': errors
|
'errors': errors
|
||||||
|
@ -62,57 +65,59 @@ class AngelHttpException implements Exception {
|
||||||
/// Throws a 400 Bad Request error, including an optional arrray of (validation?)
|
/// Throws a 400 Bad Request error, including an optional arrray of (validation?)
|
||||||
/// errors you specify.
|
/// errors you specify.
|
||||||
factory AngelHttpException.badRequest(
|
factory AngelHttpException.badRequest(
|
||||||
{String message: '400 Bad Request', List<String> errors: const []}) =>
|
{String message = '400 Bad Request',
|
||||||
|
List<String> errors = const []}) =>
|
||||||
new AngelHttpException(null,
|
new AngelHttpException(null,
|
||||||
message: message, errors: errors, statusCode: 400);
|
message: message, errors: errors, statusCode: 400);
|
||||||
|
|
||||||
/// Throws a 401 Not Authenticated error.
|
/// Throws a 401 Not Authenticated error.
|
||||||
factory AngelHttpException.notAuthenticated(
|
factory AngelHttpException.notAuthenticated(
|
||||||
{String message: '401 Not Authenticated'}) =>
|
{String message = '401 Not Authenticated'}) =>
|
||||||
new AngelHttpException(null, message: message, statusCode: 401);
|
new AngelHttpException(null, message: message, statusCode: 401);
|
||||||
|
|
||||||
/// Throws a 402 Payment Required error.
|
/// Throws a 402 Payment Required error.
|
||||||
factory AngelHttpException.paymentRequired(
|
factory AngelHttpException.paymentRequired(
|
||||||
{String message: '402 Payment Required'}) =>
|
{String message = '402 Payment Required'}) =>
|
||||||
new AngelHttpException(null, message: message, statusCode: 402);
|
new AngelHttpException(null, message: message, statusCode: 402);
|
||||||
|
|
||||||
/// Throws a 403 Forbidden error.
|
/// 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);
|
new AngelHttpException(null, message: message, statusCode: 403);
|
||||||
|
|
||||||
/// Throws a 404 Not Found error.
|
/// 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);
|
new AngelHttpException(null, message: message, statusCode: 404);
|
||||||
|
|
||||||
/// Throws a 405 Method Not Allowed error.
|
/// Throws a 405 Method Not Allowed error.
|
||||||
factory AngelHttpException.methodNotAllowed(
|
factory AngelHttpException.methodNotAllowed(
|
||||||
{String message: '405 Method Not Allowed'}) =>
|
{String message = '405 Method Not Allowed'}) =>
|
||||||
new AngelHttpException(null, message: message, statusCode: 405);
|
new AngelHttpException(null, message: message, statusCode: 405);
|
||||||
|
|
||||||
/// Throws a 406 Not Acceptable error.
|
/// Throws a 406 Not Acceptable error.
|
||||||
factory AngelHttpException.notAcceptable(
|
factory AngelHttpException.notAcceptable(
|
||||||
{String message: '406 Not Acceptable'}) =>
|
{String message = '406 Not Acceptable'}) =>
|
||||||
new AngelHttpException(null, message: message, statusCode: 406);
|
new AngelHttpException(null, message: message, statusCode: 406);
|
||||||
|
|
||||||
/// Throws a 408 Timeout error.
|
/// 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);
|
new AngelHttpException(null, message: message, statusCode: 408);
|
||||||
|
|
||||||
/// Throws a 409 Conflict error.
|
/// 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);
|
new AngelHttpException(null, message: message, statusCode: 409);
|
||||||
|
|
||||||
/// Throws a 422 Not Processable error.
|
/// Throws a 422 Not Processable error.
|
||||||
factory AngelHttpException.notProcessable(
|
factory AngelHttpException.notProcessable(
|
||||||
{String message: '422 Not Processable'}) =>
|
{String message = '422 Not Processable'}) =>
|
||||||
new AngelHttpException(null, message: message, statusCode: 422);
|
new AngelHttpException(null, message: message, statusCode: 422);
|
||||||
|
|
||||||
/// Throws a 501 Not Implemented error.
|
/// Throws a 501 Not Implemented error.
|
||||||
factory AngelHttpException.notImplemented(
|
factory AngelHttpException.notImplemented(
|
||||||
{String message: '501 Not Implemented'}) =>
|
{String message = '501 Not Implemented'}) =>
|
||||||
new AngelHttpException(null, message: message, statusCode: 501);
|
new AngelHttpException(null, message: message, statusCode: 501);
|
||||||
|
|
||||||
/// Throws a 503 Unavailable error.
|
/// 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);
|
new AngelHttpException(null, message: message, statusCode: 503);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
name: angel_http_exception
|
name: angel_http_exception
|
||||||
version: 1.0.0+3
|
version: 1.1.0
|
||||||
description: Angel's HTTP exception class.
|
description: Exception class that can be serialized to JSON and serialized to clients.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/http_exception
|
homepage: https://github.com/angel-dart/http_exception
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=1.19.0 <3.0.0"
|
sdk: ">=1.19.0 <3.0.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
dart2_constant: ^1.0.0
|
dart2_constant: ^1.0.0
|
||||||
|
dev_dependencies:
|
||||||
|
pedantic: ^1.0.0
|
Loading…
Reference in a new issue