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

HttpException: No valid statuscode. #273

Closed
ssbaval opened this issue Oct 19, 2019 · 55 comments
Closed

HttpException: No valid statuscode. #273

ssbaval opened this issue Oct 19, 2019 · 55 comments
Labels
status: fixed? Bug possibly fixed in latest version. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels

Comments

@ssbaval
Copy link

ssbaval commented Oct 19, 2019

I have sentry running and looked at my logs - for this error sentry was triggered 237 times in 1 day !.

If the URL is invalid, not found or malformed - I was under the impression that an error widget would be rendered instead ??

Exception is :

HttpException: HttpException: No valid statuscode. Statuscode was 403
  File "cache_manager.dart", line 120, in BaseCacheManager.getFile
  File "<asynchronous suspension>"
  File "cached_image_widget.dart", line 270, in CachedNetworkImageState._animatedWidget
  File "cached_image_widget.dart", line 196, in CachedNetworkImageState.build
  File "framework.dart", line 4047, in StatefulElement.build
  File "framework.dart", line 3941, in ComponentElement.performRebuild
  File "framework.dart", line 3738, in Element.rebuild
  File "framework.dart", line 3924, in ComponentElement._firstBuild
  File "framework.dart", line 4088, in StatefulElement._firstBuild
  File "framework.dart", line 3919, in ComponentElement.mount
  File "framework.dart", line 3101, in Element.inflateWidget
  File "framework.dart", line 5233, in MultiChildRenderObjectElement.mount
  File "framework.dart", line 3101, in Element.inflateWidget
  File "framework.dart", line 2904, in Element.updateChild
  File "framework.dart", line 3961, in ComponentElement.performRebuild
  File "framework.dart", line 3738, in Element.rebuild
  File "framework.dart", line 3924, in ComponentElement._firstBuild
  File "framework.dart", line 4088, in StatefulElement._firstBuild
  File "framework.dart", line 3919, in ComponentElement.mount
  File "framework.dart", line 3101, in Element.inflateWidget
  File "framework.dart", line 5233, in MultiChildRenderObjectElement.mount
  File "framework.dart", line 3101, in Element.inflateWidget
  File "framework.dart", line 5233, in MultiChildRenderObjectElement.mount

@renefloor
Copy link
Contributor

This should be improved in 1.1.2, could you try to verify that?

@guillaumeprevost
Copy link

Hello, we're building our App based on your pretty cool plugin ! Thanks for the hard work btw :)

We are running into the same issue: we're loading AWS S3 pictures dynamically, and when the picture doesn't exist, AWS S3 returns an HTTP 403 error (not 404).

Upgrading from 1.1.0 to version 1.1.3 didn't solve the issue :(

Here is the error displayed in the logs:

I/flutter ( 5123): CacheManager: Failed to download file from https://s3-ap-southeast-2.amazonaws.com/friend-theory/url/that/does/not/exist.jpg with error:
I/flutter ( 5123): HttpException: No valid statuscode. Statuscode was 403

The issue is that the exception is handled and logged by the plugin, so we don't have a way to handle it in our App if we wanted to.

Additionally, because there are a lot of pictures trying to be loaded and they fail to load, the plugin retries to download them every time the widget rebuilds, ending in:

  1. Wasted resources
  2. A lot of network calls
  3. Cluttering the logs with potentially hundreds of this log

The solutions we can suggest are to:

  • handle the exception by marking this picture as having failed to load, and retry to load it only after a certain amount of time has passed (in a way, "caching the fact that it failed to load")
  • not handle the exception in the plugin and leave it to the caller to handle it if there is an exception
  • not ideal but slightly better: simply not show this log which at least would solve point 3.

Cheers!

@renefloor renefloor added the status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels label Feb 21, 2020
@renefloor renefloor changed the title HttpException: No valid statuscode. Statuscode was 403 HttpException: No valid statuscode. Feb 21, 2020
@dspoonia7
Copy link

I'm having this issue as well. Any ETA or plans to get it fixed?

@renefloor
Copy link
Contributor

No sorry, I don't have an ETA for it. I first have to find out why it fails.

@vanlooverenkoen
Copy link

We should be able to handle the errors ourselves.

@phpirate
Copy link

It makes no sense to fail on a 404, or what ever HTTP response other than 200, this is just really annoying to simply through an exception without notifying the caller, it just makes no sense and really just because of this issue i started to consider other frameworks to use rather than Flutter, even though i love it!

@vanlooverenkoen
Copy link

vanlooverenkoen commented Apr 27, 2020

This should be fixed in the latest flutter version. Stable release will probably this week

@renefloor
Copy link
Contributor

@vanlooverenkoen how did the Flutter framework fix this? What was the PR or issue for it?

@vanlooverenkoen
Copy link

vanlooverenkoen commented Apr 30, 2020

This is fixed in the Flutter framework:
flutter/flutter#53267
flutter/flutter#53329

So flutter_cached_network_image should probably update the implementation as well.

@renefloor
Copy link
Contributor

I guess this should partly fix it for the ImageProviders, but I'm not sure if it really fixes the issues mentioned here.

@vanlooverenkoen
Copy link

You can already test this on beta. I did some testing. Our errors removed after using beta, dev or master

@netgfx
Copy link

netgfx commented May 28, 2020

So is this fixed now? Because I'm still getting this error

@renefloor
Copy link
Contributor

@netgfx do you get the errors when using the imageprovider or 2.3.0-beta?

@renefloor renefloor added the status: fixed? Bug possibly fixed in latest version. label May 28, 2020
@netgfx
Copy link

netgfx commented May 28, 2020

I'm using latest stable cached_network_image: ^2.2.0+1

Using it like this:

CachedNetworkImage(
                imageUrl: widget.list[index].thumb,
                placeholder: (context, url) => CircularProgressIndicator(),
                errorWidget: (context, url, error) => Icon(Icons.error),
                fit: BoxFit.fill,
                width: 64,
                height: 64,
              ),

When the url pulls a 404 the App crashes or in dev uncaught error is thrown.

@renefloor
Copy link
Contributor

It really crashes? I wouldn't expect that, you see it crashing?
But did you try the beta I said? Version 2.3.0-beta or 2.3.0-beta.1?

@netgfx
Copy link

netgfx commented May 28, 2020

Sometimes it crashes and other times (usually in debug mode) any other loading fails if one comes 404, all I see are spinners from that point on. I will try the beta versions and post results.

@netgfx
Copy link

netgfx commented May 29, 2020

@renefloor When I use the beta.1 I get the following error:

Leading widget consumes entire tile width. Please use a sized widget.
'package:flutter/src/material/list_tile.dart':
Failed assertion: line 1353 pos 7: 'tileWidth != leadingSize.width'

I have the image inside a ListTile like this:

ListTile(
                      contentPadding: EdgeInsets.only(
                          left: 4.0, right: 8.0, top: 4.0, bottom: 4.0),
                      leading: CachedNetworkImage(
                        imageUrl:
                            "https://www.themealdb.com/images/ingredients/" +
                                Uri.encodeComponent(item.title) +
                                ".png",
                        placeholder: (context, url) =>
                            CircularProgressIndicator(),
                        errorWidget: (context, url, error) => Icon(Icons.error),
                        fit: BoxFit.fill,
                        width: 32,
                        height: 32,
                      ),
                      title: Text(item.title, style: Styles.listText),
                      trailing: Icon(Icons.add),
                      onTap: () {
                        Navigator.of(context).pop();
                      }),

@renefloor
Copy link
Contributor

This is not related to the HttpException, and thus offtopic, but you can just add a sized box right? Didn't you have this problem with 2.2.0?

@netgfx
Copy link

netgfx commented May 29, 2020

Yes sorry for offtopic just thought it was useful to mention. No that issue didn't exist with 2.2.0 and frankly it shouldn't have because I'm already setting specific dimensions.
In terms of the http exception it is not crashing anymore, however on debug mode it still fires the uncaught error breakpoint and from that point on all other images that load in "parallel" display the spinning loader and never complete or show the error icon.

@renefloor
Copy link
Contributor

I think I can fix that size issue soon. (See Baseflow/octo_image#7)
The debugging is something that is related to the dart vm debugger which I cannot fix (easily).

For now you could disable 'break on uncaught exceptions' in the debugger settings.

@netgfx
Copy link

netgfx commented Jun 28, 2020

@aaironman Can you try without the decoration? And basically without the image builder altogether.

@aaironman
Copy link

@netgfx It doesn't work for me.Like this:
return Container(
height: 80,
width: 80,
child: ClipRRect(
borderRadius: BorderRadius.circular(6.0),
child: CachedNetworkImage(
imageUrl: imgUrl,
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
);

@netgfx
Copy link

netgfx commented Jun 28, 2020

It should really, because it doesn't need the image builder, the simplest example is:

CachedNetworkImage(
       imageUrl: "http://via.placeholder.com/350x150",
       progressIndicatorBuilder: (context, url, downloadProgress) => 
               CircularProgressIndicator(value: downloadProgress.progress),
       errorWidget: (context, url, error) => Icon(Icons.error),
    ),

but does it throw the 404 error?

@kauaicreative
Copy link

I'm using cached_network_image: ^2.3.0-beta.1 which I believe will be soon released and I no longer get the error @kauaicreative

I am testing cached_network_image: ^2.3.0-rc and it's still throwing a HttpExceptionWithStatus error
HttpException: Invalid statusCode: 404, uri = https://www.gravatar.com/avatar/35f7368e9a25b5eaf00804c65b96296b.png?s=1080&d=404&

Here is my code:

CachedNetworkImage(
          imageUrl: locator<AuthService>().userImage,
          placeholder: (context, url) => MyIcon(),
          errorWidget: (context, url, error) => MyIcon(),
          fit: BoxFit.cover,
        ),

@raphaaugustosilva
Copy link

Why is this closed? Is still happening, even with ^2.3.0-beta.1+1

@uzumaki258
Copy link

uzumaki258 commented Sep 8, 2020

it still happened. I am on version cached_network_image 2.3.1
Flutter 1.20.2

@raphaaugustosilva
Copy link

@ssbaval could you please reopen this issue?

@renefloor
Copy link
Contributor

@raphaaugustosilva can you give me a small piece of code to reproduce the issue? For example the example url that @kauaicreative gives also results in a 404 when used in the browser.

When giving a 404 the image should show the error widget. If that is not happening it is indeed a bug, but the fact that some urls are not valid is not a bug of the package.

@raphaaugustosilva
Copy link

Hi @renefloor.
I think the problem is that even with the error widget, the package is throwing an exception (not just a warning). It`s related with #433

@uzumaki258
Copy link

I back to cached_network_image: ^2.2.0+1 this issue is gone.

@kauaicreative
Copy link

cached_network_image: ^2.3.2+1
Still throwing the error, "HttpException: Invalid statusCode: 404".
@renefloor This Exception may not be technically a bug but it is annoying when developing.
If a CachedNetworkImage errorWidget exists the exception should not be thrown. The errorWidget should simply be shown.

@jeneena-jose
Copy link

jeneena-jose commented Sep 20, 2020

Having same issue on cached_network_image: ^2.3.2+1 with Flutter 1.20.4

This happens when I have a number of 404 image urls and I scroll too fast and move up in a list. Its very annoying otherwise the package is pretty cool!

Please provide a fix as soon as possible !

@vytautas-pranskunas-
Copy link

I am having same issue too. This issue is happening for a very long tme but still it exsists.

@vytautas-pranskunas-
Copy link

But I noticed that this issue was gone until I have updated to latest flutter version. I will try to downgrade in upcoming days to check.

@renefloor
Copy link
Contributor

This happens when I have a number of 404 image urls and I scroll too fast and move up in a list. Its very annoying otherwise the package is pretty cool!

What happens exactly? Do you just get the 404 in the logs, or does the app crash/freeze?

@vytautas-pranskunas-
Copy link

vytautas-pranskunas- commented Sep 23, 2020 via email

@vytautas-pranskunas-
Copy link

I found an issue. For me it was that i was sending Beare header to s3 and it was deying it. So i added condition that for auth headers would not be sent to external urls.

@khangpt
Copy link

khangpt commented Oct 2, 2020

I still got this issue on flutter 1.20.4, cached_network_image 2.3.2+1.
My app was ran in debug mode

This is how my code was operated:
freesnippingtool com_capture_20201002113243

The app will raise this exception (file: web_helper.dart):
freesnippingtool com_capture_20201002112145

freesnippingtool com_capture_20201002112225

After that, it continue calling errorWidget (I saw this log in console)
freesnippingtool com_capture_20201002112311

Hope you will fix it soon

@jmshrv
Copy link

jmshrv commented Oct 7, 2020

I get a similar error even with Flutter's Image.network. It looks like it may be an issue with Flutter, which explains why this issue has come back.

@renefloor
Copy link
Contributor

Yes, that's not really an error, it is also I/flutter with the I of info in the logs. That the debugger stops when running in debug is an issue with the dart vm, see for example also this question: https://stackoverflow.com/a/56881920/2999543

The try/catch is within the Flutter framework, so that's not really anything we can solve.

@ghost
Copy link

ghost commented Jan 2, 2021

please reopen

@renefloor
Copy link
Contributor

@ponyo877-debug why should it be reopened? The dart vm bug is unrelated to this library, so it cannot be fixed here. We should only keep issues open that should be fixed here.

@netojose
Copy link

@renefloor is correct. I having crashes debugging, but after generate an APK, everything work as expected on phone.

@Radical-Daniel
Copy link

Radical-Daniel commented Jun 10, 2021

Hi, I was experiencing this issue when using a StreamBuilder on one page of my TabBarView. I would get http error saying 403. My StreamBuilder located in the 1st tab would update when someone selects a user shown in my 2nd tab and then clicks an "Add" button. I fixed it by putting each tab into separate dart files and then calling those on a third dart file containing only the TabBar.

Other than that specific circumstance I wouldn't get this error.

@kingcut
Copy link

kingcut commented Jul 9, 2021

Screen Shot 2021-07-09 at 09 55 56
Photo url is error
I having crashes debugging.
When I build release, it is not crash but Firebase crashlytics logged this bug in dashboard
My version: cached_network_image: ^3.0.0

@uzumaki258
Copy link

Screen Shot 2021-07-09 at 09 55 56
Photo url is error
I having crashes debugging.
When I build release, it is not crash but Firebase crashlytics logged this bug in dashboard
My version: cached_network_image: ^3.0.0

it not crashes, just non-fatal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: fixed? Bug possibly fixed in latest version. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels
Projects
None yet
Development

No branches or pull requests