I got 'Document is empty' when using grape - ruby-on-rails

all
I got the error when using grape.
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
in fact, My api works and return the xml well. and after sometime's running , it start to buggy. show that error. my server is nginx + passenger. rails2.3.8. + grape. any help?

The error is from Chrome, displayed when content-type is xml and the xml is not well formed, or in your case as the error indicates, empty. Your api will still work from clients (such as curl) that do not parse and verify the content type.
It's best to hit your api with curl instead of a browser when you encounter something odd.

Related

SAPUI5 invalid MIME part type with Remote oDATA Service

I need help showing the data from my own remote server with oDATA.
When I want to show the data in the view, I get the following error
invalid MIME part type.
These are the Captures of Error
my https://******/$metadata?
My Table control from SApui5 Course App example
Error when executing the application
And Console error
When I insert this.getModel().setUseBatch(false) in the init : function () of the Component.js, it does not give me the error, nor in the console, but it does not show me the records either .. Can someone give me an idea?
It's an old question, but recently I've got the same error with batch request processing and in my case the root cause was that when building batch processing response with content type multipart/mixed you have to use CRLF as a text line separator ('\r\n') and not only '\n'. See also here in multipart response specification. The hard part was that correct and incorrect responses look absolutely identical when debugging.

ASP.NET WEB API 406 error:for POST request using Media format

I am very new to web api stuff:
I am getting an error
406: Not Acceptable
error message in asp.net web api rest service.
In my rest service I’m using media format for my customized XML output, to get customized output.
I’m registering my formatted media in Global.asax page.
GlobalConfiguration.Configuration.Formatters.Clear();
GlobalConfiguration.Configuration.Formatters.Add(new mynewformat());
all my methods are post methods with typed object as parameter and parameters are accepts from body.
Whenever I try to test the service… Getting 406: Not acceptable error message.
can anyone please help me ... what could be the reason for this....???
I did notice couple of interesting points here...
If I’m commenting below line then I’m getting 200 (OK) status code (which is fine.)... but format is not applying to output.
GlobalConfiguration.Configuration.Formatters.Clear();
If i'm removing parameters in my service method.. Then its working
fine..
I request everyone.. Please guide me what could be the reason/work around/solution/fix..for this issue.
Note:I don't want accept parameters from URI so i made it to accept from frombody only.
Thanks.
There is a lot more to implementing a custom format than just adding it to the configuration formatters. It starts with having to change the media-type header to a new custom type of your choosing (like "application/myNewFormat") for all requests, for the client. On the back end, you have to implement a new MediaTypeFormatter that can handle the serialization. This involves a bit more of code.
A good example of this resides here, it can easily be stripped to boiler-plate code:
http://www.codeproject.com/Articles/559378/Implementing-Custom-Media-Formatters-in-ASP-NET-We

Return JSON instead of HTML error page on heroku

I’m creating rails–powered app, which acts as JSON API, and is hosted on heroku.
Right now, if exception is raised, heroku returns me proper http response code, and customisable HTML page as response. However, since I’m not using HTML format, and even if I set Accept: application/json header that HTML response is returned – which is incorrect for me. Is it possible to customise response, and return some kind of JSON? (If not, response without body will be also fine)
You should catch exceptions in the controller, and head :not_found or something similar.
http://guides.rubyonrails.org/action_controller_overview.html#rescue_from
http://rails.rubyonrails.org/classes/ActionController/Base.html#M000466

Ruby Status 302 - Dont know what that means?

When i run the xxx.rb using localhost:3000/xxx I initially - before adding the require-client gem got two input boxes for name and email. that was just a basic template where you can do the usual edit/update/delete etc. However once i write the require 'rest_client' and update the gem this is what i get. Im not even sure if this is an error or if its just a way of saying rest_client was found. If so how do i go to my applicaiton to get the two boxes or get the application back up and running. i have a few more code to write to get this functionality working. however is this an intermediate state or an error ?
RestClient::Found in xxxController#index
302 Found
Rails.root: /Users/user1/Desktop/rails_projects/xxx_app
Application Trace | Framework Trace | Full Trace
app/models/xxx.rb:8
app/controllers/xxx_controller.rb:1
Request
Parameters:
None
Show session dump
Show env dump
Response
Headers:
None
This is not an error. You should look into Location header as described here: http://restpatterns.org/HTTP_Status_Codes/302_-_Found
Generally 2xx are OK good repsonses, 3xx are intermittent ones, could lead to good or bad later, 4xx are expected errors (like page not found) and 5xx are fatal server errors
I have some basic RESTful API responses outlined here (not a complete list) http://vova.org/2011/06/24/restful-http-response-codes/

Ruby on Rails: Replace a link with javascript

I have this
And I want the link to be replaced with an actual link.
So i figured I use this
page.replace_html("preview_button","<a href='/preview/#{#object.name.to_url}' class='preview' onclick='window.open(this.href);return false;'>Preview</a>")
but when I use the inspecter with chrome, it tell me
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
so... ideas?
The problem there is not your javascript replacing function. That seams to be all right.
You must inspect the link BEFORE you click the link but after the function was called, so you can see if it is being generated right.
The 500 error means that the request reached your rails controller but something wasn't right inside that.

Resources