import 'package:keyboard/utils/toast_util.dart';

import '../data/consts/error_code.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 error.code?.description ?? error.message ?? StringName.networkError;
  }

  static String _getDefaultToastMessage(String? message) {
    return message ?? StringName.networkError;
  }
}
