Last active
December 12, 2015 05:28
-
-
Save jasonelston/4721540 to your computer and use it in GitHub Desktop.
Problems with Authority, RocketPants and exceptions rendered in HTML, not JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Controller | |
class BagsController < ApiController | |
# .... | |
def index | |
authorize_action_for(Bag) | |
end | |
# .... | |
end | |
# API Controller | |
class ApiController < RocketPants::Base | |
include Devise::Controllers::Helpers | |
include ActionController::Rendering | |
include Authority::Controller | |
version 1 | |
private | |
... | |
def current_user | |
User.find_for_token_authentication(:auth_token => params[:auth_token]) | |
end | |
def authority_forbidden(error) | |
error! :forbidden #Rocketpants error method | |
end | |
end | |
# Should respond with json | |
{ | |
"error": "forbidden", | |
"error_description": "The action you requested was forbidden." | |
} | |
# Responds with html 500 | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>RocketPants::Forbidden at /api/1/shoppers/3/bags</title> | |
<style> | |
/* Basic reset */ | |
* { | |
margin: 0; | |
padding: 0; | |
} | |
table { | |
width: 100%; | |
border-collapse: collapse; | |
} | |
th, td { | |
vertical-align: top; | |
text-align: left; | |
} | |
textarea { | |
resize: none; | |
} | |
body { | |
font-size: 10pt; | |
} | |
body, td, input, textarea { | |
font-family: helvetica neue, lucida grande, sans-serif; | |
line-height: 1.5; | |
color: #333; | |
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6); | |
} | |
html { | |
background: #f0f0f5; | |
} | |
/* --------------------------------------------------------------------- | |
* Basic layout | |
* --------------------------------------------------------------------- */ | |
/* Small */ | |
@media screen and (max-width: 1100px) { | |
html { | |
overflow-y: scroll; | |
} | |
body { | |
margin: 0 20px; | |
} | |
header.exception { | |
margin: 0 -20px; | |
} | |
nav.sidebar { | |
padding: 0; | |
margin: 20px 0; | |
} | |
ul.frames { | |
max-height: 200px; | |
overflow: auto; | |
} | |
} | |
.... etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment