Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 HttpExceptions #504

Closed
2 tasks done
Peng-Qian opened this issue Nov 24, 2020 · 14 comments
Closed
2 tasks done

404 HttpExceptions #504

Peng-Qian opened this issue Nov 24, 2020 · 14 comments

Comments

@Peng-Qian
Copy link

Peng-Qian commented Nov 24, 2020

🔙 Regression

Old (and correct) behavior

When the URL is invalid(the image fails to load), the console print the error info once, and there are no exceptions.

Current behavior

When the URL is invalid(the image fails to load) and if there two more CachedNetwrokImage with that invalid URL, the following error info repetitively prints in the console, and then it will show the exceptions.

Screenshot

Screen Shot 2020-11-24 at 8 53 59 PM

Error Info

I/flutter ( 6648): CacheManager: Failed to download file from https://... with error:
I/flutter ( 6648): HttpException: Invalid statusCode: 404, uri = https://...

Exception

════════ Exception caught by image resource service ════════════════════════════════════════════════
The following HttpExceptionWithStatus was thrown resolving an image codec:
HttpException: Invalid statusCode: 404, uri = https://...

When the exception was thrown, this was the stack: 
Image provider: CachedNetworkImageProvider("https://...", scale: 1.0) 
 Image key: CachedNetworkImageProvider("https://...", scale: 1.0): CachedNetworkImageProvider("https://...", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

Reproduction steps

create two more CachedNetworkImage widgets with the same invalid URL, and reload them a few times.

try to go to the image view screen a few times on the following example app, you will get the above issue.

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

void main() => runApp(LabApp());

const invalidUrl =
    'https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_into.jpg';

class LabApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Lab',
      theme: ThemeData(
        primarySwatch: Colors.blueGrey,
        backgroundColor: Colors.white,
      ),
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Home Screen'),
      ),
      body: SizedBox.expand(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            CachedNetworkImage(
              imageUrl: invalidUrl,
              errorWidget: (context, url, error) => Icon(Icons.error),
            ),
            RaisedButton(
              child: Text('Click Me'),
              onPressed: () => Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => ImageView(),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class ImageView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Image View'),
      ),
      body: Center(
        child: CachedNetworkImage(
          imageUrl: invalidUrl,
          errorWidget: (context, url, error) => Icon(Icons.error),
        ),
      ),
    );
  }
}

Configuration

N/A

Version: 2.3.3

Platform:

  • 📱 iOS
  • 🤖 Android
@alr2413
Copy link

alr2413 commented Jan 10, 2021

I've encountered the same issue, any solution?

@thongvo109
Copy link

me too :(

@thongvo109
Copy link

My solution:
I think you should give this package a try. Perhaps it can fix it. I tried
cached_network_image: ^2.0.0-rc

@fryette
Copy link

fryette commented Jan 26, 2021

@renefloor do you have any plans to take a look at that bug in near future?
In our project we have a lot of images that can fail and during debugging really struggling with it

@renefloor
Copy link
Contributor

The printing is done by the ImageStreamCompleter, which means I would need to fork that and I don't prefer to do that.
That the debugger pauses is being worked on by the Dart VM team, but I don't expect it to be fully fixed soon. You can disabled 'break on exceptions' though, this is a screenshot from intellij:
image

@fryette
Copy link

fryette commented Jan 29, 2021

@renefloor,
Thanks for your answer.
But disabling exception handling at all is not an option. You can miss very important exceptions during development especially when you have a big team working on the same codebase.

Probably it is possible to implement something like that?
flutter/flutter#20910 (comment)

@renefloor
Copy link
Contributor

But this is just not trying to get the image when you don't have an internet connection. That would break the offline caching though. Getting the state from the ImageProvider to the Image widget needs to be done by throwing an exception.

@0wzZZzz6
Copy link

I just encountered this one too.

@ramonpaolo
Copy link

I have the same problem now : (
Some solution?

@alexrainman
Copy link

Same problem here.

@renefloor
Copy link
Contributor

I'm sorry, but there is not really a solution, as this is how Dart and Flutter works. I'm closing this issue because it is not fixable by this library.

@hoangtrholly
Copy link

I have the same problem now
Is there any solution right now

@lukeirvin
Copy link

Seeing the same issue as well. Any updates?

@DainoJung
Copy link

This happens when calling a specific URL (such as an image posted on Github). Changing the URL address is the only solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests