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

ARRAY: Api request returned invalid json (Airborne::InvalidJsonError) #129

Open
papitodev opened this issue Mar 27, 2017 · 6 comments
Open

Comments

@papitodev
Copy link

papitodev commented Mar 27, 2017

I am sending a request inside an array, but an error 500 occurs with the message: Error: Api request returned invalid json (Airborne::InvalidJsonError)

  @req = []
  body = {
    name: 'Paul Robias',
    email: '[email protected]',
    actualDate: '2017-03-27T17:19:21.944Z',
    deviceCode: 'XPTODEVCODE123'
  }

  @req.push(body)

    post 'http://127.0.0.1/user', @req, {"Content-Type" => 'application/json'}
    puts json_body

    

This problem does not happen when I use Httparty. :(

@papitodev
Copy link
Author

up

@papitodev
Copy link
Author

Rest Client does not accept json body with array ??

@papitodev
Copy link
Author

up

2 similar comments
@papitodev
Copy link
Author

up

@papitodev
Copy link
Author

up

@rdalverny
Copy link
Contributor

I believe the culprit could be airborne/rest_client_requester.rb#L10:

module Airborne
  module RestClientRequester
    def make_request(method, url, options = {})
      headers = base_headers.merge(options[:headers] || {})
      res = if method == :post || method == :patch || method == :put
        begin
          request_body = options[:body].nil? ? '' : options[:body]
          request_body = request_body.to_json if options[:body].is_a?(Hash)
          RestClient.send(method, get_url(url), request_body, headers)
...

rdalverny pushed a commit to rdalverny/airborne that referenced this issue Aug 4, 2017
Until now, the request body is only serialized if it's a Hash.
But it could be an Array, or any other serializable type,
and those bodies are serialized. See brooklynDev#129, probably brooklynDev#141 as well.

I am not sure if this wouldn't break use cases where
the body is already expected to be serialized.
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

No branches or pull requests

2 participants