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

properly reject promise in cloudinary provider #13992

Merged
merged 4 commits into from Aug 12, 2022

Conversation

Marc-Roig
Copy link
Contributor

@Marc-Roig Marc-Roig commented Aug 5, 2022

πŸ‘‹πŸ» What does it do?

  • Properly reject and throw an error when there is an issue uploading a file to cloudinary.

@gvocale provided the solution for the issue already.

❓ Why is it needed?

Cloudinary errors were not handled properly, and the server was crashing.

πŸ§ͺ How to test it?

  • Have a Cloudinary account for the provider options ( ask me if you need some and feel lazy ). Add them to the plugin configuration.
  • Upload a pdf bigger than 10Mb in the media folder (Cloudinary free tier limit) (PDF I used)

You should see this error when trying to upload it:
image

πŸ€” Concerns

  • When rejecting the promise with the PayloadTooLargeError error (or any other) I see this log on the console:
info: In application test-middleware middleware.
This error originated either by throwing inside an async function without a catch block or rejecting a promise not handled with .catch(). The promise was rejected with the reason:
{
  message: 'File size too large. Got 10615705. Maximum is 10485760.',
  name: 'Error',
  http_code: 400
}

I am not understanding why it is appearing or how to prevent it.

πŸ”— Related issue(s)/PR(s)

Let us know if this is related to any issue/pull request

@Marc-Roig Marc-Roig added source: core:upload Source is core/upload package pr: fix This PR is fixing a bug labels Aug 5, 2022
@Marc-Roig Marc-Roig added this to the 4.3.3 milestone Aug 5, 2022
@codecov
Copy link

codecov bot commented Aug 5, 2022

Codecov Report

Merging #13992 (2148c4f) into master (d49d687) will decrease coverage by 5.96%.
The diff coverage is 100.00%.

❗ Current head 2148c4f differs from pull request most recent head 8668ba9. Consider uploading reports for the commit 8668ba9 to get more accurate results

@@            Coverage Diff             @@
##           master   #13992      +/-   ##
==========================================
- Coverage   55.34%   49.38%   -5.97%     
==========================================
  Files        1258      263     -995     
  Lines       31702     9287   -22415     
  Branches     5735     2019    -3716     
==========================================
- Hits        17546     4586   -12960     
+ Misses      12340     3877    -8463     
+ Partials     1816      824     -992     
Flag Coverage Ξ”
front ?
unit 49.38% <100.00%> (+0.79%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
.github/actions/check-pr-status/index.js 91.30% <100.00%> (ΓΈ)
...core/utils/lib/sanitize/visitors/allowed-fields.js 88.88% <0.00%> (-4.87%) ⬇️
packages/core/utils/lib/validators.js 85.71% <0.00%> (-1.08%) ⬇️
packages/core/upload/server/utils/file.js 21.73% <0.00%> (-0.99%) ⬇️
...e/utils/lib/sanitize/visitors/restricted-fields.js 12.50% <0.00%> (-0.84%) ⬇️
.../core/upload/server/services/image-manipulation.js 67.36% <0.00%> (-0.72%) ⬇️
...n/server/migrations/field/migrate-for-bookshelf.js 22.50% <0.00%> (-0.58%) ⬇️
packages/plugins/i18n/server/services/core-api.js 34.40% <0.00%> (-0.38%) ⬇️
.../core/admin/server/validation/common-validators.js 81.33% <0.00%> (-0.25%) ⬇️
packages/plugins/i18n/server/services/locales.js 95.45% <0.00%> (-0.11%) ⬇️
... and 1097 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@alexandrebodin alexandrebodin removed this from the 4.3.3 milestone Aug 10, 2022
@petersg83 petersg83 force-pushed the fix/cloudinary-provider-missing-catch branch from e545e6b to 9ddf2f6 Compare August 11, 2022 14:13
@petersg83 petersg83 changed the base branch from master to releases/4.3.0 August 11, 2022 14:14
@petersg83 petersg83 changed the base branch from releases/4.3.0 to master August 11, 2022 14:14
petersg83
petersg83 previously approved these changes Aug 11, 2022
Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

LGTM! I tried with cloudinary. Works as expected

petersg83
petersg83 previously approved these changes Aug 11, 2022
@Marc-Roig Marc-Roig merged commit 288dc33 into master Aug 12, 2022
@Marc-Roig Marc-Roig deleted the fix/cloudinary-provider-missing-catch branch August 12, 2022 08:58
@Marc-Roig Marc-Roig added this to the 4.3.5 milestone Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:upload Source is core/upload package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants