Upgrade http_exception
This commit is contained in:
parent
6875451993
commit
c5e7de1b97
2 changed files with 19 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
|||
library angel_http_exception;
|
||||
|
||||
import 'package:dart2_constant/convert.dart';
|
||||
//import 'package:dart2_constant/convert.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
/// Exception class that can be serialized to JSON and serialized to clients.
|
||||
/// Carries HTTP-specific metadata, like [statusCode].
|
||||
|
@ -45,11 +46,11 @@ class AngelHttpException implements Exception {
|
|||
|
||||
@override
|
||||
String toString() {
|
||||
return "$statusCode: $message";
|
||||
return '$statusCode: $message';
|
||||
}
|
||||
|
||||
factory AngelHttpException.fromMap(Map data) {
|
||||
return new AngelHttpException(
|
||||
return AngelHttpException(
|
||||
null,
|
||||
statusCode: (data['status_code'] ?? data['statusCode']) as int,
|
||||
message: data['message']?.toString(),
|
||||
|
@ -60,64 +61,64 @@ class AngelHttpException implements Exception {
|
|||
}
|
||||
|
||||
factory AngelHttpException.fromJson(String str) =>
|
||||
new AngelHttpException.fromMap(json.decode(str) as Map);
|
||||
AngelHttpException.fromMap(json.decode(str) as Map);
|
||||
|
||||
/// Throws a 400 Bad Request error, including an optional arrray of (validation?)
|
||||
/// errors you specify.
|
||||
factory AngelHttpException.badRequest(
|
||||
{String message = '400 Bad Request',
|
||||
List<String> errors = const []}) =>
|
||||
new AngelHttpException(null,
|
||||
AngelHttpException(null,
|
||||
message: message, errors: errors, statusCode: 400);
|
||||
|
||||
/// Throws a 401 Not Authenticated error.
|
||||
factory AngelHttpException.notAuthenticated(
|
||||
{String message = '401 Not Authenticated'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 401);
|
||||
AngelHttpException(null, message: message, statusCode: 401);
|
||||
|
||||
/// Throws a 402 Payment Required error.
|
||||
factory AngelHttpException.paymentRequired(
|
||||
{String message = '402 Payment Required'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 402);
|
||||
AngelHttpException(null, message: message, statusCode: 402);
|
||||
|
||||
/// Throws a 403 Forbidden error.
|
||||
factory AngelHttpException.forbidden({String message = '403 Forbidden'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 403);
|
||||
AngelHttpException(null, message: message, statusCode: 403);
|
||||
|
||||
/// Throws a 404 Not Found error.
|
||||
factory AngelHttpException.notFound({String message = '404 Not Found'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 404);
|
||||
AngelHttpException(null, message: message, statusCode: 404);
|
||||
|
||||
/// Throws a 405 Method Not Allowed error.
|
||||
factory AngelHttpException.methodNotAllowed(
|
||||
{String message = '405 Method Not Allowed'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 405);
|
||||
AngelHttpException(null, message: message, statusCode: 405);
|
||||
|
||||
/// Throws a 406 Not Acceptable error.
|
||||
factory AngelHttpException.notAcceptable(
|
||||
{String message = '406 Not Acceptable'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 406);
|
||||
AngelHttpException(null, message: message, statusCode: 406);
|
||||
|
||||
/// Throws a 408 Timeout error.
|
||||
factory AngelHttpException.methodTimeout({String message = '408 Timeout'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 408);
|
||||
AngelHttpException(null, message: message, statusCode: 408);
|
||||
|
||||
/// Throws a 409 Conflict error.
|
||||
factory AngelHttpException.conflict({String message = '409 Conflict'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 409);
|
||||
AngelHttpException(null, message: message, statusCode: 409);
|
||||
|
||||
/// Throws a 422 Not Processable error.
|
||||
factory AngelHttpException.notProcessable(
|
||||
{String message = '422 Not Processable'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 422);
|
||||
AngelHttpException(null, message: message, statusCode: 422);
|
||||
|
||||
/// Throws a 501 Not Implemented error.
|
||||
factory AngelHttpException.notImplemented(
|
||||
{String message = '501 Not Implemented'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 501);
|
||||
AngelHttpException(null, message: message, statusCode: 501);
|
||||
|
||||
/// Throws a 503 Unavailable error.
|
||||
factory AngelHttpException.unavailable(
|
||||
{String message = '503 Unavailable'}) =>
|
||||
new AngelHttpException(null, message: message, statusCode: 503);
|
||||
AngelHttpException(null, message: message, statusCode: 503);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ description: Exception class that can be serialized to JSON and serialized to cl
|
|||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/http_exception
|
||||
environment:
|
||||
sdk: ">=2.10.0 <2.12.0"
|
||||
dependencies:
|
||||
dart2_constant: ^1.0.0
|
||||
sdk: ">=2.10.0 <3.0.0"
|
||||
dev_dependencies:
|
||||
pedantic: ^1.0.0
|
||||
pedantic: ^1.11.0
|
Loading…
Reference in a new issue