json_http_error 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bb39d32eeabbe2434f84a30ca083bd6ae5df8ab
4
+ data.tar.gz: d04b762d8d3f9d16d8722d671c60c3de3bea867f
5
+ SHA512:
6
+ metadata.gz: 9101fe1be3b7ddf12a0860a066461999409709d1d7f71e3e40eb45e355553e7547a5ed4dda65ec48e11c10dd98ab917bf09bb5508d39d0ef168e7f9666a01e4b
7
+ data.tar.gz: 493cda77fae4179b81a56d3f91e970301a9110686742df38eb1378155327da688ce5a6f8a19ce8d4c37c8f99cd07750956e66192ca192b3f6831469144947bb8
@@ -0,0 +1,46 @@
1
+ en:
2
+ http_status:
3
+ # Source: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error
4
+ 400: Bad Request
5
+ 401: Unauthorized
6
+ 402: Payment Required
7
+ 403: Forbidden
8
+ 404: Not Found
9
+ 405: Method Not Allowed
10
+ 406: Not Acceptable
11
+ 407: Proxy Authentication Required
12
+ 408: Request Timeout
13
+ 409: Conflict
14
+ 410: Gone
15
+ 411: Length Required
16
+ 412: Precondition Failed
17
+ 413: Request Entity Too Large
18
+ 414: Request-URI Too Long
19
+ 415: Unsupported Media Type
20
+ 416: Requested Range Not Satisfiable
21
+ 417: Expectation Failed
22
+ 418: I'm a teapot
23
+ 419: Authentication Timeout
24
+ 420: Method Failure
25
+ 420: Enhance Your Calm
26
+ 421: Misdirected Request
27
+ 422: Unprocessable Entity
28
+ 423: Locked
29
+ 424: Failed Dependency
30
+ 426: Upgrade Required
31
+ 428: Precondition Required
32
+ 429: Too Many Requests
33
+ 431: Request Header Fields Too Large
34
+ 440: Login Timeout
35
+ 444: No Response
36
+ 449: Retry With
37
+ 450: Blocked by Windows Parental Controls
38
+ 451: Unavailable For Legal Reasons
39
+ 451: Redirect
40
+ 494: Request Header Too Large
41
+ 495: Cert Error
42
+ 496: No Cert
43
+ 497: HTTP to HTTPS
44
+ 498: Token expired/invalid
45
+ 499: Client Closed Request
46
+ 499: Token required
@@ -0,0 +1,28 @@
1
+ class JsonHttpError < StandardError
2
+ VERSION = '0.0.1'.freeze
3
+
4
+ attr_accessor :code, :opts
5
+
6
+ def initialize(error_code, error_opts = {})
7
+ @code = error_code
8
+ @opts = error_opts.with_indifferent_access
9
+ end
10
+
11
+ def code
12
+ @code
13
+ end
14
+
15
+ def reply
16
+ reply = { status: 'ERROR', code: code, message: I18n.t("http_status.#{code}", opts) }
17
+ reply = reply.merge(opts[:json]) if opts[:json]
18
+ reply
19
+ end
20
+
21
+ def to_proc
22
+ binded_reply = reply
23
+ binded_code = code
24
+ Proc.new do
25
+ render status: binded_code, json: { error: binded_reply }
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_http_error
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Arnaud 'red' Rouyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: DRY module for APIs to render HTTP errors in JSON
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - config/locales/en.yml
20
+ - lib/json_http_error.rb
21
+ homepage: https://github.com/savemysmartphone/json_http_error
22
+ licenses: []
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.5
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: DRY module for APIs to render HTTP errors in JSON
44
+ test_files: []