error.dart 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import 'package:flowy_sdk/protobuf/dart-ffi/protobuf.dart';
  2. class FlowyInternalError {
  3. late FFIStatusCode _statusCode;
  4. late String _error;
  5. FFIStatusCode get statusCode {
  6. return _statusCode;
  7. }
  8. String get error {
  9. return _error;
  10. }
  11. bool get has_error {
  12. return _statusCode != FFIStatusCode.Ok;
  13. }
  14. String toString() {
  15. return "$_statusCode: $_error";
  16. }
  17. FlowyInternalError({required FFIStatusCode statusCode, required String error}) {
  18. _statusCode = statusCode;
  19. _error = error;
  20. }
  21. factory FlowyInternalError.from(FFIResponse resp) {
  22. return FlowyInternalError(statusCode: resp.code, error: "");
  23. }
  24. }
  25. class StackTraceError {
  26. Object error;
  27. StackTrace trace;
  28. StackTraceError(
  29. this.error,
  30. this.trace,
  31. );
  32. FlowyInternalError asFlowyError() {
  33. return FlowyInternalError(statusCode: FFIStatusCode.Err, error: this.toString());
  34. }
  35. String toString() {
  36. return '${error.runtimeType}. Stack trace: $trace';
  37. }
  38. }