Skip to content

service-worker: configure response status codes to treat as failed/offline with freshness strategy #45954

@anton-marchenko

Description

@anton-marchenko

Which @angular/* package(s) are the source of the bug?

service-worker

Is this a regression?

No

Description

Expected behaviour: freshness strategy should return to user fetching requested data only if request was successful.
If request is unsuccessful (has 500, 504 and other codes) it should return cached result instead of bad result. And bad result should not be cached at all.

But in reality:

freshness strategy return for user bad results.

Interestingly, freshness strategy works as expected if web-server absolutely died (network error: connection refused). I mean, all configured in dataGroup requests begin to return from cache and web-application works despite dead backend. It is different with particular bad request (as I described above).

Performance strategy works as expected (it returns cached results firstly)

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 11.2.19
Node: 14.8.2
OS: darwin x64

Angular: 11.2.14

Anything else?

https://angular.io/guide/service-worker-config#datagroups

https://stackoverflow.com/questions/69132411/angular-service-worker-return-cached-response-if-server-returns-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: service-workerIssues related to the @angular/service-worker packagefeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under consideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions