-
Notifications
You must be signed in to change notification settings - Fork 37
Check for error before writing new file in client.Store() #8
Conversation
|
Hello @chetanyakan Thank you for this PR.
Indeed, I was expected the line Concerning your conversion issue, did you use the latest version of Gotenberg? |
client.go
Outdated
| defer resp.Body.Close() | ||
|
|
||
| // Check for 2XX Status Codes | ||
| if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply check res.StatutsCode != http.StatusOK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed I was not aware whether gotenberg returns any non-200 (2XX) status codes upon successful conversion to pdf.
If the status code is expected to be 200 always, you can let me know and I can make the required change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the expected status code is always excepted to be 200 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
Regarding my issue, I was using |
Version 6 should behave way better on that issue 👍 |
|
Thank you 😄 👍 |
Summary
Prevent creation of a corrupted file if the file conversion fails.
Explain the motivation for making this change. What existing problem does the pull request solve?
I tried converting a ppt file to pdf. Due to some memory or time issue (I wasn't able to figure out the cause), the file failed to convert and a corrupted file of ~57B was written instead, which could not be opened in a PDF viewer.
For reference, the following error was in the Gotenberg logs:
I expected the client.Store() method to return an error instead of writing a corrupted file.
Test plan (required)
Demonstrate the code is solid. Example: The exact commands you ran and their output.
Checklist
make lint)?make tests)?