paulschneider / b247-api

0 stars 0 forks source link

Really strange thing #51

Closed pablocarrillo closed 10 years ago

pablocarrillo commented 10 years ago

If I put the address on chrome I get the JSON, but if I do the same with the python scripts or the iOS App I get a 500 error

This is the log:

---- REQUEST ----
Method: GET uri: http://api.wf-cycle.co.uk/articles
---- CLIENT HEADERS ----
{
    "Accept": "application/json", 
    "BristolAPIClient": "iphone", 
    "content-type": "application/json"
}
---- CLIENT PAYLOAD----
{
    "article": 142, 
    "category": 5, 
    "subchannel": 53
}
---- RESPONSE ----
http://api.wf-cycle.co.uk/articles?category=5&article=142&subchannel=53
---- SERVER HEADERS ----
x-powered-by PHP/5.4.28
set-cookie laravel_session=eyJpdiI6IjZLYU9KVW9qeVUwYSswbGZrUmd6ZmFGa1wvUDhEajNxWGFYWmF1dlBBTW5vPSIsInZhbHVlIjoiZkFza1wvSTI4Zk1NTkNzUktMTHNoZWY3OXllWUp1U1NcL1BybGdxNmMrS3ZNYjlZTFFCTllianVEYzY1SDNXZUZKQmFSVHJyYWsreGY5R04zaGR2Z21MUT09IiwibWFjIjoiMTUyMTU3Njc2ZmZkNWNjNjEzMDNjYjkyNDNmOWE5YTVkZmM2ZDVlMjg3MWI1ZGZmMjgwZDM0MTlmMmRkN2JmYiJ9; expires=Wed, 23-Jul-2014 15:21:53 GMT; path=/; httponly
server Apache/2.2.27 (Unix) mod_ssl/2.2.27 OpenSSL/1.0.1e-fips mod_bwlimited/1.4 PHP/5.4.28
connection close
cache-control no-cache
date Wed, 23 Jul 2014 13:21:53 GMT
x-frame-options SAMEORIGIN
content-type text/html
---- SERVER CODE ----
500
---- SERVER PAYLOAD ----
{
    "error": {
        "file": "/home/wfcycle/public_html/api/b247-api/web/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php", 
        "line": 68, 
        "message": "Server error response [url] http://app.wf-staging.co.uk/app/article [status code] 500 [reason phrase] Internal Server Error", 
        "type": "GuzzleHttp\\Exception\\ServerException"
    }
}

The weird thing is I am taking directly the address from the log and paste in on chrome and everything is good

paulschneider commented 10 years ago

Hmm....I wold say there is no issue with the web based version you see in Chrome because you get the HTML back. If there was an error on the frontend where the templates are stored then you wouldn't get back the HTML, just an error.

If you call http://app.wf-staging.co.uk/app/article, which is the URL the API calls to get the HTML then you get the error because it wont accept a GET request (only) post and requires certain params the API provides when it does its POST.

Hmmm..... Let me have a think.

Does your test script do anything other than make a GET request to http://api.wf-cycle.co.uk/articles?subchannel=71&category=17&article=226

pablocarrillo commented 10 years ago

Not, neither the app and I just made a simple curl to the address and it works. This getting more and more strange ...

pablocarrillo commented 10 years ago

Ok, I found the culprit.

if I do not send the BristolAPIClient it works, so at this moment I am going to a deactivate I think this need you to accept it in the server.

paulschneider commented 10 years ago

Why does that break it for you?

Im only using that at the moment to determine whether I should send back mobile only data or the web version.

pablocarrillo commented 10 years ago

Well I agree that is very strange indeed but as soon I take off the header the thing works, and if I put it back break again. maybe are you passing that header also to the frontend?

pablocarrillo commented 10 years ago

I can also reproduce the error in the Advanced RestClient for Chrome adding the header to the get request screen shot 2014-07-23 at 14 57 46

paulschneider commented 10 years ago

.....if I change the BristolAPIClient header to anything else, BristolAPIClient1 for example, it works.

If I remove the HTML response from the front end and replace it with any string, it works.

pablocarrillo commented 10 years ago

Maybe the front end and the API use that to talk to each other, but with some other meaning?

paulschneider commented 10 years ago

Right I know why its doing it..... For every call you make to the API you send the BristolApiClient header variable. This is used throughout the system to remove the data you dont usually want to see, such as URL paths (because you use ID's), alt and title tags for images and so on.

However in the case of the article call some of this information is needed to populate the HTML template. So, because we are removing the information as we get the article details its then not available in the object that populates the template and is causing an error on the front end server.

Im going to need to implement a different transformer that ignores the header param and returns everything so the template has it all there to work with I think.

paulschneider commented 10 years ago

This should be fixed for you now. Phew. That was a tough one!

pablocarrillo commented 10 years ago

Indeed ! Many thanks