title: How can I have Grape return error messages in CSV format?
body: <p>I have a Rails app and I have implemented api using <a href="https://github.com/intridea/grape" rel="nofollow">Grape</a> gem. Now, I created a custom error formatter (CSVFormatter) to return error response in CSV format.</p>
  
  <p>And, also I have this in my application's v2.rb file:</p>
  
  <pre><code>error_formatter :csv, Api::Base::Errors::CSVFormatter
  </code></pre>
  
  <p>When I hit a url like this:</p>
  
  <p><a href="http://example.com/api/v2/datasets/CODE/data.csv?&amp;trim_start=06/01/99&amp;trim_end=2014-05/28&amp;sort_order=desc" rel="nofollow">http://example.com/api/v2/datasets/CODE/data.csv?&amp;trim_start=06/01/99&amp;trim_end=2014-05/28&amp;sort_order=desc</a></p>
  
  <p>It shows the error in the console like this which is good and means that my custom error formatter is working properly:</p>
  
  <pre><code>Error 
  trim_start is invalid 
  trim_end is invalid
  </code></pre>
  
  <p>But, I just need to download this error message in a csv file. After looking at Grape's documentation, I found a way of setting Content-type and I tried this:</p>
  
  <pre><code>      rack = Rack::Response.new(as_csv , 422, { "Content-type" =&gt; "text/csv" }).finish
        rack[2].body[0]
  </code></pre>
  
  <p>But, this is not working as I expected.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Looks like there is no clean way of doing it using grape <strong>without forcefully overriding the status code</strong> according to the answer of Simon. But, one may not wish to do that as it may result other issues in the application like if some other program tries to read the data from the api and gets the incorrect response or so even without knowing why.</p>