Code Monkey home page Code Monkey logo

Comments (12)

chaptermediadevelopment avatar chaptermediadevelopment commented on August 18, 2024

for clarity, with lazt loading off, this same error occurs on simple:

2.0.0p247 :013 > WhichArticle.find(12344)
ActiveRestClient::ResponseParseException: ActiveRestClient::ResponseParseException
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active-rest-client-52f5068f4145/lib/active_rest_client/request.rb:208:in `rescue in handle_response'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active-rest-client-52f5068f4145/lib/active_rest_client/request.rb:175:in `handle_response'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active-rest-client-52f5068f4145/lib/active_rest_client/request.rb:74:in `block in call'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active-rest-client-52f5068f4145/lib/active_rest_client/request.rb:50:in `call'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active-rest-client-52f5068f4145/lib/active_rest_client/mapping.rb:33:in `_call'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/bundler/gems/active-rest-client-52f5068f4145/lib/active_rest_client/mapping.rb:23:in `block in _map_call'
        from (irb):13
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
        from /Users/finalarena/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

from active-rest-client.

andyjeffries avatar andyjeffries commented on August 18, 2024

Could you possibly give me a small demo file that defines where the API is and the classes involved so I can look in to it please? You can paste it in here...

Alternatively, as it's a parse error, have you looked at making the same API call yourself using cURL and seeing what the response is?

Normally this happens if Tomcat vomits out an HTML error page instead of it being nicely trapped with a JSON response.

@jcavell any chance you can have a look in to (delegate to the appropriate people) our APIs; if we say "Accept: application/json" any Tomcat errors should be trapped and a JSON response returned instead.

from active-rest-client.

chaptermediadevelopment avatar chaptermediadevelopment commented on August 18, 2024

I got the attached json from your tem that defines the api so far (load into Postman):

{"id":"7136f07f-bedc-bf31-52b6-c64876876977","name":"Content API - Staging","timestamp":1378115275694,"requests":[{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"0061473c-d314-da73-19c3-860bbdbf71e6","name":"Get panel by valid id","description":"","url":"https://staging.services.which.co.uk/content/v1/panels/trusted-traders/4234","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"495e452f-a934-7b64-24b3-b569c56a4c86","name":"Get video by malformed id","description":"","url":"https://staging.services.which.co.uk/content/v1/videos/trusted-traders/un-recognisedid","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"4c67b728-cc14-1d1d-f2ab-843c4132f9e8","name":"Get person by malformed id","description":"","url":"https://staging.services.which.co.uk/content/v1/people/trusted-traders/un-recognisedid","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"5eb41917-0ef8-0fe7-b0a4-3c20b5aff113","name":"Get person by valid id","description":"","url":"https://staging.services.which.co.uk/content/v1/people/trusted-traders/9876","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"62f0a33f-014e-e301-8ac0-bbeb1fbfff3d","name":"Get article by valid id","description":"","url":"https://staging.services.which.co.uk/content/v1/articles/trusted-traders/12344","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"7d5a17e7-1ecc-a55e-a299-a73f798be8b1","name":"Get article by invalid id","description":"","url":"https://staging.services.which.co.uk/content/v1/articles/trusted-traders/56789","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"85a55361-c36c-92e3-59ae-619aa2607a35","name":"Get image by invalid id","description":"","url":"https://staging.services.which.co.uk/content/v1/images/trusted-traders/4564","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"917b7ebe-ca6d-9f31-47c9-737c6b3f7f2b","name":"Get article by malformed id","description":"","url":"https://staging.services.which.co.uk/content/v1/articles/trusted-traders/dfdf","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"a2e85fdf-55a1-9a83-3123-016f08882977","name":"Get link by invalid id","description":"","url":"https://staging.services.which.co.uk/content/v1/links/trusted-traders/100","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"a7629fe0-e5a1-03bd-98bc-f5850d9cb6be","name":"Get panel by invalid id","description":"","url":"https://staging.services.which.co.uk/content/v1/panels/trusted-traders/98","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"a7a05d59-5bde-76da-3487-2013ec17d74a","name":"Get link by malformed id","description":"","url":"https://staging.services.which.co.uk/content/v1/links/trusted-traders/un-recognisedid","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"b188b452-a50e-b386-c049-da46bdff61a3","name":"Get panel by malformed id","description":"","url":"https://staging.services.which.co.uk/content/v1/panels/trusted-traders/unrecognisedid","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"b5ce137e-0a88-d2fc-0692-244e41b33044","name":"Get person by invalid id","description":"","url":"https://staging.services.which.co.uk/content/v1/people/trusted-traders/100","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"b8d3d5cd-09d6-9d43-e9d8-2a6542a346c5","name":"Get video by valid id","description":"","url":"https://staging.services.which.co.uk/content/v1/videos/trusted-traders/5678","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"ba7b43ea-adb0-6e57-e690-ab537a346219","name":"Get image by malformed id","description":"","url":"https://staging.services.which.co.uk/content/v1/images/trusted-traders/InvalidId","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"bdaee604-82df-8f0a-a374-7b74bcd98983","name":"Get link with invalid api key","description":"","url":"https://staging.services.which.co.uk/content/v1/links/trusted-traders/12343","method":"GET","headers":"X-API-Key: VEVTdffdsfVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"c87a2bc2-1d80-2af1-248d-2a43a296ea7d","name":"Get image by valid id","description":"","url":"https://staging.services.which.co.uk/content/v1/images/trusted-traders/1244","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"de527080-485b-e63e-c3ab-941416c33d93","name":"Get link by valid id","description":"","url":"https://staging.services.which.co.uk/content/v1/links/trusted-traders/12343","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2},{"collectionId":"7136f07f-bedc-bf31-52b6-c64876876977","id":"ea844c48-d501-c2e6-12de-a7144dffdbfe","name":"Get video by invalid id","description":"","url":"https://staging.services.which.co.uk/content/v1/videos/trusted-traders/100","method":"GET","headers":"X-API-Key: VEVTVC1LRVk=\n","data":[],"dataMode":"params","timestamp":0,"responses":[],"version":2}]}

from active-rest-client.

chaptermediadevelopment avatar chaptermediadevelopment commented on August 18, 2024

Can we get some log/debugging support in the gem? To help debug we really need to be able to toggle verbose logging where we can see the requests made and response objects.

from active-rest-client.

andyjeffries avatar andyjeffries commented on August 18, 2024

Definitely a fair point, I'll add verbose mode now so you can send me the entire log snippet afterwards.

from active-rest-client.

andyjeffries avatar andyjeffries commented on August 18, 2024

OK, verbose mode added - https://github.com/whichdigital/active-rest-client#debugging

Please attach the verbose output here for the request (so the parent call and the lazy loaded sub-resource).

from active-rest-client.

chaptermediadevelopment avatar chaptermediadevelopment commented on August 18, 2024

"Invalid X-API-Key"

This key, works in other rest clients accessing this article.

  �[1;4;32mActiveRestClient�[0m WhichArticle#find - Requesting https://staging.services.which.co.uk/content/v1/articles/trusted-traders/12344
ActiveRestClient Verbose Log:
  > Accept : application/hal+json, application/json;q=0.5
  > X-API-Key : VEVTVC1LRVk=
  > 
  < Date : Wed, 11 Sep 2013 11:16:08 GMT
  < WWW-Authenticate : Invalid X-API-Key
  < Content-Type : application/json;charset=UTF-8
  < Content-Length : 0
  < Keep-Alive : timeout=2, max=500
  < Connection : Keep-Alive
  < Set-Cookie : bIPs=78c233f966bf604cfc26eb62fb889ba4;path=/;
  < 

I'd also suggest this should go to console, as it does in most Rails logging and not just the log file.

Here is my active concern:


module WhichConcern
  extend ActiveSupport::Concern

  included do
    base_url "https://staging.services.which.co.uk/content/v1"
    #lazy_load!
    #perform_caching true
    verbose! if Rails.env.development?
    before_request :add_authentication_details
    @site_identifier = 'trusted-traders'
  end

  def add_authentication_details(name, request)
    request.headers["X-API-Key"] = 'VEVTVC1LRVk='
  end

end

I think we need a way to gracefully catch these and not result in a generic ActiveRestClient::HTTPClientException, i.e. in Her when i add auth middleware, i can have it throw both middleware and auth specific exceptions back, so some how in before_request :add_authentication_details we need to be able to control exceptions raised by code in callbacks.

from active-rest-client.

chaptermediadevelopment avatar chaptermediadevelopment commented on August 18, 2024

In fact, is often the case that auth headers are positively excluded from logfiles, so you have to tap log output (like a console window) to see that dangerous detail.

from active-rest-client.

andyjeffries avatar andyjeffries commented on August 18, 2024

OK, taking these points one by one:

  1. It should work as of v0.9.8 - there was a bug where it wasn't actually sending any custom headers (including the X-API-Key one). It sends them now

  2. Logging output is sent using Rails.logger, this output is sent by Rails wherever it's configured to go (the console, the log file, both, wherever). The code that actually sends the log output is the ActiveRestClient::Logger class which uses Rails.logger if it's available and a logfile if not - in case ARC is used outside of Rails.

  3. It now throws an HTTPUnauthorisedClientException for 401, HTTPForbiddenClientException for 403 and HTTPNotFoundClientException for 404 - all are descendants of HTTPClientException so existing code trapping that will still work.

  4. I don't follow what you mean by trapping exceptions raised by code in callbacks, the request handling code has no idea where parts of the request came from and couldn't narrow down a response to an entire HTTP request to an individual part of the code.

  5. I'm not worried about excluding auth headers from logfiles as they are only logged in verbose which should not be enabled on production apps anyway.

Let me know if all is working OK for you now.

from active-rest-client.

chaptermediadevelopment avatar chaptermediadevelopment commented on August 18, 2024

Can you bump the version number in the version file so i can reference 0.9.8 in gemfile?

from active-rest-client.

andyjeffries avatar andyjeffries commented on August 18, 2024

I deleted the v0.9.8 tag and recreated it after updating the version file. Hope that's OK for you...

from active-rest-client.

chaptermediadevelopment avatar chaptermediadevelopment commented on August 18, 2024

perfect :)

from active-rest-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.