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

fix(service-worker): continue serving api requests on cache failure #32996

Closed

Conversation

apocalyp0sys
Copy link
Contributor

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

When responses are cached ok during sw initialization, but caching throws an error when handling api response, this response never gets to client.

Issue Number: #21412

What is the new behavior?

Fix response delivery by catching errors and add 2 test cases.

Does this PR introduce a breaking change?

  • Yes
  • No

@apocalyp0sys apocalyp0sys requested a review from a team as a code owner October 4, 2019 10:37
@atscott atscott added the area: service-worker Issues related to the @angular/service-worker package label Oct 4, 2019
@ngbot ngbot bot added this to the needsTriage milestone Oct 4, 2019
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, @apocalyp0sys! This goes into the right direction. (Also, love the tests 😍)
I have left a couple of suggestions. In addition, could you split up the PR into two commits: a refactor one to add the lru parameter to safeCacheResponse (since that is actually unrelated to the fix) and a fix one to actually fix the bug?

packages/service-worker/worker/test/happy_spec.ts Outdated Show resolved Hide resolved
packages/service-worker/worker/src/data.ts Show resolved Hide resolved
Make safe caching and unsafe caching methods compatible so they can be
swapped. Gives more flexibility when writing http response processing
code.
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thx for making the changes, @apocalyp0sys 👍
I left a couple more minor comments, but otherwise lgtm 🎉

packages/service-worker/worker/src/app-version.ts Outdated Show resolved Hide resolved
packages/service-worker/worker/src/data.ts Outdated Show resolved Hide resolved
@gkalpak gkalpak added state: WIP target: patch This PR is targeted for the next patch release type: bug/fix labels Oct 14, 2019
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! Almost there 😅

packages/service-worker/worker/test/happy_spec.ts Outdated Show resolved Hide resolved
packages/service-worker/worker/test/happy_spec.ts Outdated Show resolved Hide resolved
packages/service-worker/worker/test/happy_spec.ts Outdated Show resolved Hide resolved
When responses are cached ok during sw initialization,
but caching throws an error when handling api response,
this response never gets to client. Fix response
delivery by catching errors, add logging and 2 test cases.

Fixes angular#21412
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉 Thx, @apocalyp0sys! ❤️

@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker and removed state: WIP labels Oct 14, 2019
@mhevery mhevery added target: major This PR is targeted for the next major release and removed target: patch This PR is targeted for the next patch release labels Oct 14, 2019
@mhevery
Copy link
Contributor

mhevery commented Oct 14, 2019

I was unable to merge this to the patch branch as it causes conflicts. Could we create a new PR for patch branch?

@mhevery mhevery closed this in 1353afc Oct 14, 2019
mhevery pushed a commit that referenced this pull request Oct 14, 2019
…32996)

When responses are cached ok during sw initialization,
but caching throws an error when handling api response,
this response never gets to client. Fix response
delivery by catching errors, add logging and 2 test cases.

Fixes #21412

PR Close #32996
@apocalyp0sys
Copy link
Contributor Author

Should i create a new PR targeting 8.2.x branch?

@gkalpak
Copy link
Member

gkalpak commented Oct 15, 2019

Yes, please, @apocalyp0sys 🙏

apocalyp0sys added a commit to apocalyp0sys/angular that referenced this pull request Oct 15, 2019
…le (angular#32996)

Make safe caching and unsafe caching methods compatible so they can be
swapped. Gives more flexibility when writing http response processing
code.

PR Close angular#32996

(cherry picked from commit 1353afc)
apocalyp0sys added a commit to apocalyp0sys/angular that referenced this pull request Oct 15, 2019
When responses are cached ok during sw initialization,
but caching throws an error when handling api response,
this response never gets to client. Fix response
delivery by catching errors, add logging and 2 test cases.
Same changes for master branch in PR angular#32996

Fixes angular#21412
mhevery pushed a commit that referenced this pull request Oct 15, 2019
…le (#32996) (#33165)

Make safe caching and unsafe caching methods compatible so they can be
swapped. Gives more flexibility when writing http response processing
code.

PR Close #32996

(cherry picked from commit 1353afc)

PR Close #33165
mhevery pushed a commit that referenced this pull request Oct 15, 2019
…33165)

When responses are cached ok during sw initialization,
but caching throws an error when handling api response,
this response never gets to client. Fix response
delivery by catching errors, add logging and 2 test cases.
Same changes for master branch in PR #32996

Fixes #21412

PR Close #33165
ODAVING pushed a commit to ODAVING/angular that referenced this pull request Oct 18, 2019
…le (angular#32996)

Make safe caching and unsafe caching methods compatible so they can be
swapped. Gives more flexibility when writing http response processing
code.

PR Close angular#32996
ODAVING pushed a commit to ODAVING/angular that referenced this pull request Oct 18, 2019
…ngular#32996)

When responses are cached ok during sw initialization,
but caching throws an error when handling api response,
this response never gets to client. Fix response
delivery by catching errors, add logging and 2 test cases.

Fixes angular#21412

PR Close angular#32996
AndrusGerman pushed a commit to AndrusGerman/angular that referenced this pull request Oct 22, 2019
…le (angular#32996)

Make safe caching and unsafe caching methods compatible so they can be
swapped. Gives more flexibility when writing http response processing
code.

PR Close angular#32996
AndrusGerman pushed a commit to AndrusGerman/angular that referenced this pull request Oct 22, 2019
…ngular#32996)

When responses are cached ok during sw initialization,
but caching throws an error when handling api response,
this response never gets to client. Fix response
delivery by catching errors, add logging and 2 test cases.

Fixes angular#21412

PR Close angular#32996
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: service-worker Issues related to the @angular/service-worker package cla: yes target: major This PR is targeted for the next major release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants