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

Fixed bug caused by calling Poison.encode! on an empty request body #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stringlytyped
Copy link

In Togglex.json_request, the argument body is encoded to JSON using the Poison.encode! function. The default value for this argument is an empty string ("").

Calling Poison.encode! on an empty string returns "\"\"". In the past, Toggl's servers would process requests issued with this request body without issue. However, sometime within the last few months, the behavior of the API changed. Now when a request is submitted to Toggl with this value in the request body, Toggl returns an HTML page with an "invalid request" message.

This results in a :connect_timeout exception being raised (in version 0.2.0 of Togglex) when calling certain functions, such as Togglex.Reports.summary. (In version 0.1.0, a "Unexpected token" exception is raised.)

This pull request adds a check in the Togglex.json_request function that skips the call to Poison.encode! if body is empty.

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.5%) to 18.462% when pulling 5b91004 on stringlytyped:bug-fix/unexpected-token into 4b8d310 on diacode:master.

@stringlytyped
Copy link
Author

Looks like the build is failing because String.trim used to be called String.strip in Elixir 1.2.0 (which Travis CI is configured to use when compiling).

@stringlytyped stringlytyped mentioned this pull request Apr 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants