restful_error 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -6
- data/app/views/restful_error/show.html.haml +3 -2
- data/app/views/restful_error/show.json.jbuilder +1 -0
- data/app/views/restful_error/show.xml.erb +5 -1
- data/config/locales/ja.restful_error.yml +2 -2
- data/lib/restful_error/version.rb +1 -1
- data/lib/restful_error.rb +4 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c7576aafad158add3451d2470a10828e9533a8
|
4
|
+
data.tar.gz: bade50c831d2d7a894f61c0745b762980ffe9170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
15
|
+
Load the module in your controller:
|
16
16
|
|
17
|
-
|
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
|
-
#=> {
|
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><
|
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
|
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,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:
|
11
|
+
internal_server_error: サーバエラーです #500
|
12
12
|
service_unavailable: サービスが一時的に利用不可能になっています。しばらく時間をおいて、再度ご確認願います。 #503
|
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
|
-
@
|
27
|
-
|
28
|
-
|
29
|
-
|
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.
|
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
|
+
date: 2014-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|