Changed statusCode and message to be not nullable

This commit is contained in:
thomashii 2021-04-09 21:38:31 +08:00
parent d65a0e7c83
commit 526c761846

View file

@ -15,23 +15,21 @@ class AngelHttpException implements Exception {
final List<String> errors = []; final List<String> errors = [];
/// The cause of this exception. /// The cause of this exception.
String? message; String message;
/// The [StackTrace] associated with this error. /// The [StackTrace] associated with this error.
StackTrace? stackTrace; StackTrace? stackTrace;
/// An HTTP status code this exception will throw. /// An HTTP status code this exception will throw.
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) {
this.errors.addAll(errors); this.errors.addAll(errors);
} }
}
Map toJson() { Map toJson() {
return { return {
@ -52,8 +50,8 @@ class AngelHttpException implements Exception {
factory AngelHttpException.fromMap(Map data) { factory AngelHttpException.fromMap(Map data) {
return AngelHttpException( return AngelHttpException(
null, null,
statusCode: (data['status_code'] ?? data['statusCode']) as int?, statusCode: (data['status_code'] ?? data['statusCode'] ?? 500) as int,
message: data['message']?.toString(), message: data['message']?.toString() ?? 'Internal Server Error',
errors: data['errors'] is Iterable errors: data['errors'] is Iterable
? ((data['errors'] as Iterable).map((x) => x.toString()).toList()) ? ((data['errors'] as Iterable).map((x) => x.toString()).toList())
: <String>[], : <String>[],