Skip to content

Commit

Permalink
fix: remove excessive network image error logs. (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
Livinglist authored Sep 20, 2024
1 parent a50c456 commit c24670d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
9 changes: 8 additions & 1 deletion lib/repositories/hacker_news_web_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/foundation.dart';
import 'package:hacki/config/constants.dart';
import 'package:hacki/config/locator.dart';
import 'package:hacki/cubits/cubits.dart';
import 'package:hacki/extensions/extensions.dart';
import 'package:hacki/models/models.dart';
import 'package:hacki/repositories/hacker_news_repository.dart';
import 'package:hacki/utils/utils.dart';
Expand All @@ -18,7 +19,7 @@ import 'package:html/parser.dart';
import 'package:html_unescape/html_unescape.dart';

/// For fetching anything that cannot be fetched through Hacker News API.
class HackerNewsWebRepository {
class HackerNewsWebRepository with Loggable {
HackerNewsWebRepository({
RemoteConfigCubit? remoteConfigCubit,
HackerNewsRepository? hackerNewsRepository,
Expand Down Expand Up @@ -144,6 +145,7 @@ class HackerNewsWebRepository {
(elements.elementAt(index), subtextElements.elementAt(index)),
);
} on DioException catch (e) {
logError('error fetching stories on page $page: $e');
if (_rateLimitedStatusCode.contains(e.response?.statusCode)) {
throw RateLimitedWithFallbackException(e.response?.statusCode);
}
Expand Down Expand Up @@ -280,6 +282,7 @@ class HackerNewsWebRepository {
return parsedIds;
} on DioException catch (e) {
if (_rateLimitedStatusCode.contains(e.response?.statusCode)) {
logError('error fetching favorites on page $page: $e');
throw RateLimitedException(e.response?.statusCode);
}
throw GenericException();
Expand Down Expand Up @@ -358,6 +361,7 @@ class HackerNewsWebRepository {
return elements;
} on DioException catch (e) {
if (_rateLimitedStatusCode.contains(e.response?.statusCode)) {
logError('error fetching comments on page $page: $e');
throw RateLimitedWithFallbackException(e.response?.statusCode);
}
throw GenericException();
Expand Down Expand Up @@ -503,4 +507,7 @@ class HackerNewsWebRepository {
)
.trim();
}

@override
String get logIdentifier => 'HackerNewsWebRepository';
}
50 changes: 29 additions & 21 deletions lib/screens/widgets/link_preview/link_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,37 +115,45 @@ class LinkView extends StatelessWidget {
child: SizedBox(
height: layoutHeight,
width: layoutHeight,
child: CachedNetworkImage(
imageUrl: imageUri ?? '',
fit: isIcon ? BoxFit.scaleDown : BoxFit.fitWidth,
cacheKey: imageUri,
errorWidget: (_, __, ___) {
if (url.isEmpty) {
return FadeIn(
child: imageUri == null && url.isEmpty
? FadeIn(
child: Center(
child: _HackerNewsImage(
height: layoutHeight,
),
),
);
}
return Center(
child: CachedNetworkImage(
imageUrl: Constants.favicon(url),
fit: BoxFit.scaleDown,
cacheKey: iconUri,
)
: CachedNetworkImage(
imageUrl: imageUri ?? Constants.favicon(url),
fit: isIcon ? BoxFit.scaleDown : BoxFit.fitWidth,
cacheKey: imageUri,
errorWidget: (_, __, ___) {
return const FadeIn(
child: Icon(
Icons.public,
size: Dimens.pt20,
if (url.isEmpty) {
return FadeIn(
child: Center(
child: _HackerNewsImage(
height: layoutHeight,
),
),
);
}
return Center(
child: CachedNetworkImage(
imageUrl: Constants.favicon(url),
fit: BoxFit.scaleDown,
cacheKey: iconUri,
errorWidget: (_, __, ___) {
return const FadeIn(
child: Icon(
Icons.public,
size: Dimens.pt20,
),
);
},
),
);
},
),
);
},
),
),
),
)
Expand Down

0 comments on commit c24670d

Please sign in to comment.