import 'package:clean/utils/toast_util.dart';
import 'package:get/get.dart';
import '../resource/string.gen.dart';
import 'http_handler.dart';

class ErrorHandler {
  ErrorHandler._();

  static void toastError(dynamic error, {String? message}) {
    String toastMessage = (error is ServerErrorException)
        ? _getToastMessageFromError(error)
        : _getDefaultToastMessage(message);
    ToastUtil.show(toastMessage);
  }

  static String _getToastMessageFromError(ServerErrorException error) {
    return getErrorCodeMsg(error.code) ??
        error.message ?? "connect error";
  }

  static String? getErrorCodeMsg(int? code) {
    String? msg;
    // switch (code) {
    //   case ErrorCode.errorCodeNoLogin:
    //     msg = StringName.errorCodeNoLogin;
    //     break;
    // }
    return msg;
  }

  static String _getDefaultToastMessage(String? message) {
    return message ?? "connect error";
  }
}
