how do I tell rails to not render html for json requests? -


if make curl request api endpoint , there problem (in development), see:

>curl --user me:mypassword http://localhost:3000/api/v1/magic_endpoint.json  <!doctype html> <html lang="en"> <head>   <meta charset="utf-8" />   <title>action controller: exception caught</title>   <style>   ... stuff     <body>      <header>       <h1>         activerecord::pendingmigrationerror       </h1>     </header>   ... more stuff 

which annoying , obnoxious. how can tell rails not return html when json asked for? have seen many questions similar on here answers redirect 404/500 in routes.rb custom errors controller , manually render json 'internal error' or 'not found', not want that. rails outputting actual error, in case, activerecord::pendingmigrationerror, , don't want hide that.. don't want have visually parse bunch of html markup figure out error is.

you add

  # raise exceptions instead of rendering exception templates.   config.action_dispatch.show_exceptions = false 

to config/environments/development.rb, that'd turn off exception-to-response conversion completely, wouldn't http status code, , no trace of exception in response's body.

i guess want exception-to-response conversion 'magically' happen, still, json result. don't think stock rails can configured (short of monkey-patching actiondispatch::exceptionwrapper, particular magic happens). there might gems (ruby libraries) provide rails engines enable rails want.

does have curl?

to explore behavior of api implementation, writing automated tests or request specs might better suited manually querying curl. , ones pin down wanted behavior can kept around , run during development, they'll tell when behavior unexpectedly changes.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -