Changed statusCode and message to be not nullable
This commit is contained in:
parent
d65a0e7c83
commit
526c761846
1 changed files with 5 additions and 7 deletions
|
@ -15,22 +15,20 @@ 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() {
|
||||||
|
@ -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>[],
|
||||||
|
|
Loading…
Reference in a new issue