Hi! :wave: I leave a small contribution here, thank you for developing this gem. This error happened to me in a system I'm working on and I use a workaround to handle it, but I thought it might be useful if I fix the error directly in the gem, hope you like it!
When a user tries to create a new assignment in a project the gem does the next:
POST /v2/projects/{PROJECT_ID}/user_assignments
The problem is that the PROJECT_ID could be nil (in the worst-case scenario), so the response of Harvest API is an HTML body (in a string) with 404 HTTP code.
Harvesting tries to parse this HTML as a JSON and fails
def create(entity)
url = "#{DEFAULT_HOST}/#{entity.path}"
uri = URI(url)
response = http_response(:post, uri, body: entity.to_hash)
entity.attributes = JSON.parse(response.body) #### this line
entity
end
This raises a JSONParse::Error because is trying to parse an HTML response, and this error is not being rescued anywhere and handling it in a proper way. This PR fixes that situation :)
Summary
Added Harvesting::RequestNotFound to errors.rb.
Added Harvesting::RequestNotFound rescue to client.rb.
Hi! :wave: I leave a small contribution here, thank you for developing this gem. This error happened to me in a system I'm working on and I use a workaround to handle it, but I thought it might be useful if I fix the error directly in the gem, hope you like it!
refers to https://github.com/fastruby/harvesting/issues/55
What changes does this PR include?
Description
When a user tries to create a new assignment in a project the gem does the next:
POST /v2/projects/{PROJECT_ID}/user_assignments
The problem is that the
PROJECT_ID
could benil
(in the worst-case scenario), so the response of Harvest API is an HTML body (in a string) with404
HTTP code.Harvesting tries to parse this HTML as a JSON and fails
This raises a
JSONParse::Error
because is trying to parse an HTML response, and this error is not being rescued anywhere and handling it in a proper way. This PR fixes that situation :)Summary
Harvesting::RequestNotFound
toerrors.rb
.Harvesting::RequestNotFound
rescue toclient.rb
.