restful_error 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a0b6ecf7b2b0850d7ba6f851e133a14956e14ba
4
- data.tar.gz: e13b73de0f1cd601fa9e9625e88947d6f4a5c778
3
+ metadata.gz: 19c7576aafad158add3451d2470a10828e9533a8
4
+ data.tar.gz: bade50c831d2d7a894f61c0745b762980ffe9170
5
5
  SHA512:
6
- metadata.gz: c724eaf4017d222802139f57968badb47ddbbf9449e1fa28d274dc1504fd52944286bea4fa984e308664830f0afc69ed377c3c435135c6b5b3e4fe7715b45604
7
- data.tar.gz: a97290cf9558f780b32dde51e76ebd01353a1451303a60fd39dc89aec061dd97f32a216f8a2e5d74c8962d82e052579fc9a72da252c473f0cd143e05f63e6c91
6
+ metadata.gz: 0586cb161caac54f9aacf4233ad6352a36c93b9809475fded81c2a5fb473b0d9fe7cac861a18d438201fdffe73d0e01dea62fca5f677574638342da4277f9a76
7
+ data.tar.gz: 5c4f5cba5c88cb538df49695ec93a18ca32aa6a0b3fa6240dec82afadbf676d1b99f631e83b3fd949b062ca271f65016b0985a0979b2e19aac8c0739f76e10cb
data/README.md CHANGED
@@ -12,9 +12,13 @@ And then execute:
12
12
 
13
13
  $ bundle
14
14
 
15
- Or install it yourself as:
15
+ Load the module in your controller:
16
16
 
17
- $ gem install restful_error
17
+ ```ruby
18
+ class ApplicationController < ActionController::Base
19
+
20
+ include RestfulError::ActionController
21
+ ```
18
22
 
19
23
  ## Usage
20
24
 
@@ -36,10 +40,10 @@ get '/posts/new'
36
40
  #=> render 'restful_error/show.html' with @status_code and @message
37
41
 
38
42
  post '/posts.json'
39
- #=> { status: 401, message: "Sign in required"} or write your json at 'restful_error/show.json'
43
+ #=> { status_code: 401, message: "Sign in required"} or write your json at 'restful_error/show.json'
40
44
 
41
45
  get '/session.xml'
42
- #=> "<error><status type="integer">401</status><message>Sign in required</message></error>" or write your xml at 'restful_error/show.xml'
46
+ #=> "<error><status_code type="integer">401</status_code><message>Sign in required</message></error>" or write your xml at 'restful_error/show.xml'
43
47
  ```
44
48
 
45
49
  #### I18n
@@ -89,6 +93,7 @@ ja:
89
93
  active_record/record_not_found: 要求されたリソースが存在しません
90
94
  ```
91
95
  #### custom message
96
+
92
97
  ```ruby
93
98
  class RequireLogin < StandardError
94
99
  def initialize(provider = 'Unknown')
@@ -97,13 +102,12 @@ class RequireLogin < StandardError
97
102
  def status_code
98
103
  :unauthorized
99
104
  end
100
- def message
105
+ def status_message
101
106
  I18n.t('restful_error.require_login', provider: provider)
102
107
  end
103
108
  end
104
109
  ```
105
110
 
106
-
107
111
  ## Contributing
108
112
 
109
113
  1. Fork it ( https://github.com/kuboon/restful_error/fork )
@@ -1,4 +1,5 @@
1
1
  .page_header
2
2
  %h1
3
- = @message
4
- %small= @status_code
3
+ = @status_code
4
+ = @reason_phrase
5
+ %p= @message
@@ -1,2 +1,3 @@
1
1
  json.status_code @status_code
2
+ json.reason_phrase @reason_phrase
2
3
  json.message @message
@@ -1 +1,5 @@
1
- <error><status_code><%= @status_code %></status_code><message><%= @message %></message></error>
1
+ <error>
2
+ <status_code><%= @status_code %></status_code>
3
+ <reason_phrase><%= @reason_phrase %></reason_phrase>
4
+ <message><%= @message %></message>
5
+ </error>
@@ -1,6 +1,6 @@
1
1
  ja:
2
2
  restful_error:
3
- active_record/record_not_found: 要求されたリソースが存在しません!
3
+ active_record/record_not_found: 要求されたリソースが存在しません
4
4
  can_can/unauthorized: 権限がありません
5
5
  bad_request: 不正なリクエストです #400
6
6
  unauthorized: 権限がありません #401
@@ -8,5 +8,5 @@ ja:
8
8
  not_found: そのURLは存在しません #404
9
9
  method_not_allowed: メソッドは使用できません #405
10
10
  gone: 要求されたリソースは消滅しました #410
11
- internal_server_error: サーバエラーです。 #500
11
+ internal_server_error: サーバエラーです #500
12
12
  service_unavailable: サービスが一時的に利用不可能になっています。しばらく時間をおいて、再度ご確認願います。 #503
@@ -1,3 +1,3 @@
1
1
  module RestfulError
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/restful_error.rb CHANGED
@@ -23,11 +23,10 @@ module RestfulError
23
23
  @status_code = Rack::Utils.status_code(@exception.try(:status_code)).nonzero? || ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
24
24
  raise if @status_code == 500 && Rails.configuration.consider_all_requests_local
25
25
 
26
- @message = @exception.message
27
- default_message = @exception.class.new.message rescue nil
28
-
29
- if @message == default_message
30
- reason_phrase_key = RestfulError.reason_phrase(@status_code).downcase.gsub(/\s|-/, '_').to_sym
26
+ @reason_phrase = RestfulError.reason_phrase(@status_code)
27
+ @message = @exception.try(:status_message)
28
+ unless @message
29
+ reason_phrase_key = @reason_phrase.downcase.gsub(/\s|-/, '_').to_sym
31
30
  @message = I18n.t @exception.class.name.underscore, default: [reason_phrase_key, @exception.class.name], scope: :restful_error
32
31
  end
33
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_error
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kuboon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails