Frontend first draft
This commit is contained in:
43
frontend/pshared/lib/api/responses/error/server.dart
Normal file
43
frontend/pshared/lib/api/responses/error/server.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'server.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class ErrorResponse implements Exception {
|
||||
final int code;
|
||||
final String details;
|
||||
final String source;
|
||||
final String error;
|
||||
|
||||
const ErrorResponse({
|
||||
required this.code,
|
||||
required this.details,
|
||||
required this.error,
|
||||
required this.source,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final buffer = StringBuffer('Error response (code: $code');
|
||||
|
||||
if (details.isNotEmpty) {
|
||||
buffer.write(', details: $details');
|
||||
}
|
||||
|
||||
if (error.isNotEmpty) {
|
||||
buffer.write(', error: $error');
|
||||
}
|
||||
|
||||
if (source.isNotEmpty) {
|
||||
buffer.write(', source: $source');
|
||||
}
|
||||
|
||||
buffer.write(')');
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
factory ErrorResponse.fromJson(Map<String, dynamic> json) => _$ErrorResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ErrorResponseToJson(this);
|
||||
}
|
||||
Reference in New Issue
Block a user