nullIfNotFound<T> function

Future<T?> nullIfNotFound<T>(
  1. Future<T?> fetchFunction(
    1. RequestConfig requestConfig
    ), {
  2. RequestConfig? requestConfig,
})

Implementation

Future<T?> nullIfNotFound<T>(
    Future<T?> Function(RequestConfig requestConfig) fetchFunction,
    {RequestConfig? requestConfig}) async {
  try {
    return await fetchFunction(
        requestConfig ?? RequestConfig(ignoreErrors: true));
  } catch (e) {
    if (e is ThingsboardError &&
        e.errorCode == ThingsBoardErrorCode.itemNotFound) {
      return null;
    } else {
      rethrow;
    }
  }
}