-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ce85bc
commit 2e177a6
Showing
6 changed files
with
72 additions
and
85 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,12 @@ class Api::V1::BaseController < ApplicationController | |
before_filter :check_format! | ||
before_filter :check_auth_token! | ||
|
||
# something, somewhere, somehow is causing find_by_id to | ||
# raise an exception when it shouldn't. Therefore: | ||
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
viktorshamal
Author
Contributor
|
||
|
||
rescue_from CanCan::AccessDenied do |exception| | ||
render status: 401, | ||
json: { | ||
success: false, | ||
info: t('api.flash.unauthorized'), | ||
errors: t('api.flash.unauthorized') | ||
} | ||
unauthorized | ||
end | ||
|
||
private | ||
|
@@ -44,4 +43,27 @@ def check_format! | |
end | ||
end | ||
|
||
def success(info=nil, options={}) | ||
json_response 200, true, info, data:options | ||
end | ||
|
||
def failure(resource) | ||
json_response 400, false, nil, errors: resource.errors.full_messages | ||
end | ||
|
||
def unauthorized | ||
json_response 401, false, t('api.flash.unauthorized'), errors: t('api.flash.unauthorized') | ||
end | ||
|
||
def record_not_found(resource_name=nil) | ||
json_response 404, false, resource_name.to_s + ' ' + t('api.flash.not_found'), errors: resource_name.to_s + ' ' + t('api.flash.not_found') | ||
end | ||
|
||
def json_response(status, success, info, options={}) | ||
render status: status, | ||
json: ({ | ||
success: success, | ||
info: info, | ||
}).merge(options) | ||
end | ||
end |
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
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
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
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
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
we must be able to look at the backtrace to see where the problem occurd? this seems like a hack