From 7950f8170b45d2a450e56b119984916e12509376 Mon Sep 17 00:00:00 2001 From: appflowy Date: Sat, 21 May 2022 21:58:46 +0800 Subject: [PATCH] chore: optimaze error code --- .../application/grid/cell/date_cal_bloc.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart index a0ba35f9d6..2e70ecddb2 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart @@ -1,6 +1,7 @@ import 'package:app_flowy/workspace/application/grid/field/field_service.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-error-code/code.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -91,7 +92,7 @@ class DateCalBloc extends Bloc { case ErrorCode.InvalidDateTimeFormat: emit(state.copyWith( dateData: Some(newDateData), - timeFormatError: Some(err.toString()), + timeFormatError: Some(messageFromFlowyError(err)), )); break; default: @@ -101,6 +102,18 @@ class DateCalBloc extends Bloc { ); } + String messageFromFlowyError(FlowyError error) { + switch (ErrorCode.valueOf(error.code)!) { + case ErrorCode.EmailFormatInvalid: + return state.copyWith(isSubmitting: false, emailError: some(error.msg), passwordError: none()); + case ErrorCode.PasswordFormatInvalid: + return state.copyWith(isSubmitting: false, passwordError: some(error.msg), emailError: none()); + default: + return state.copyWith(isSubmitting: false, successOrFail: some(right(error))); + } + return ""; + } + @override Future close() async { if (_onCellChangedFn != null) {