railerr 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
+ SHA256:
3
+ metadata.gz: 8d4bd95812d58ddf87e8b5a1d8deb962f3c10d329ad32108c537d0e8e5df1c16
4
+ data.tar.gz: 86311328d87f4a159f6495ba15c1cc592b22e62eb1cccebc7226d33784f1c9c3
5
+ SHA512:
6
+ metadata.gz: b46e3748f88ba6a72c236f0ba1f0f5a23def27253e488f685e1ca1c7b788e4ae834646bb404846b73c4745d86eb2c2ab73ab423190bc1c50bbf6be859704b0e3
7
+ data.tar.gz: 8e73380426e860f6a9b2a1a95a8adfed7e7def951e44ce235e39f21f6e45aa4c4aae5fadc88c7526b07d41552fe0466b50dba964e994e0ed972b6cc79baa4f80
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'status'
4
+
5
+ module Railerr
6
+ # Base Exception class to raise exceptions associated with HTTP errors
7
+ class APIException < StandardError
8
+ DEFAULT_MESSAGE = 'A server error occurred'
9
+ STATUS_CODE = Status::HTTP_500_INTERNAL_SERVER_ERROR
10
+
11
+ def initialize(message = nil)
12
+ super(message || default_message)
13
+ end
14
+
15
+ def default_message
16
+ self.class::DEFAULT_MESSAGE
17
+ end
18
+
19
+ def status_code
20
+ self.class::STATUS_CODE
21
+ end
22
+ end
23
+
24
+ # Raised for HTTP 400 Bad Request
25
+ class BadRequestError < APIException
26
+ DEFAULT_MESSAGE = 'Bad request'
27
+ STATUS_CODE = Status::HTTP_400_BAD_REQUEST
28
+ end
29
+
30
+ # Raised for HTTP 500 Internal Server Errors
31
+ class InternalServerError < APIException
32
+ DEFAULT_MESSAGE = 'Internal server error'
33
+ end
34
+
35
+ # Raised for HTTP 423 Locked
36
+ class LockedError < APIException
37
+ DEFAULT_MESSAGE = 'Locked'
38
+ STATUS_CODE = Status::HTTP_423_LOCKED
39
+ end
40
+
41
+ # Raised for HTTP 404 Not Found.
42
+ class NotFoundError < APIException
43
+ DEFAULT_MESSAGE = 'Not found'
44
+ STATUS_CODE = Status::HTTP_404_NOT_FOUND
45
+ end
46
+
47
+ # Raised for HTTP 422 Unprocessable Content
48
+ class UnprocessableContentError < APIException
49
+ DEFAULT_MESSAGE = 'Unprocessable content'
50
+ STATUS_CODE = Status::HTTP_422_UNPROCESSABLE_ENTITY
51
+ end
52
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Railerr
4
+ module Status
5
+ HTTP_100_CONTINUE = 100
6
+ HTTP_101_SWITCHING_PROTOCOLS = 101
7
+ HTTP_102_PROCESSING = 102
8
+ HTTP_103_EARLY_HINTS = 103
9
+ HTTP_200_OK = 200
10
+ HTTP_201_CREATED = 201
11
+ HTTP_202_ACCEPTED = 202
12
+ HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203
13
+ HTTP_204_NO_CONTENT = 204
14
+ HTTP_205_RESET_CONTENT = 205
15
+ HTTP_206_PARTIAL_CONTENT = 206
16
+ HTTP_207_MULTI_STATUS = 207
17
+ HTTP_208_ALREADY_REPORTED = 208
18
+ HTTP_226_IM_USED = 226
19
+ HTTP_300_MULTIPLE_CHOICES = 300
20
+ HTTP_301_MOVED_PERMANENTLY = 301
21
+ HTTP_302_FOUND = 302
22
+ HTTP_303_SEE_OTHER = 303
23
+ HTTP_304_NOT_MODIFIED = 304
24
+ HTTP_305_USE_PROXY = 305
25
+ HTTP_306_RESERVED = 306
26
+ HTTP_307_TEMPORARY_REDIRECT = 307
27
+ HTTP_308_PERMANENT_REDIRECT = 308
28
+ HTTP_400_BAD_REQUEST = 400
29
+ HTTP_401_UNAUTHORIZED = 401
30
+ HTTP_402_PAYMENT_REQUIRED = 402
31
+ HTTP_403_FORBIDDEN = 403
32
+ HTTP_404_NOT_FOUND = 404
33
+ HTTP_405_METHOD_NOT_ALLOWED = 405
34
+ HTTP_406_NOT_ACCEPTABLE = 406
35
+ HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407
36
+ HTTP_408_REQUEST_TIMEOUT = 408
37
+ HTTP_409_CONFLICT = 409
38
+ HTTP_410_GONE = 410
39
+ HTTP_411_LENGTH_REQUIRED = 411
40
+ HTTP_412_PRECONDITION_FAILED = 412
41
+ HTTP_413_REQUEST_ENTITY_TOO_LARGE = 413
42
+ HTTP_414_REQUEST_URI_TOO_LONG = 414
43
+ HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415
44
+ HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416
45
+ HTTP_417_EXPECTATION_FAILED = 417
46
+ HTTP_418_IM_A_TEAPOT = 418
47
+ HTTP_421_MISDIRECTED_REQUEST = 421
48
+ HTTP_422_UNPROCESSABLE_ENTITY = 422
49
+ HTTP_423_LOCKED = 423
50
+ HTTP_424_FAILED_DEPENDENCY = 424
51
+ HTTP_425_TOO_EARLY = 425
52
+ HTTP_426_UPGRADE_REQUIRED = 426
53
+ HTTP_428_PRECONDITION_REQUIRED = 428
54
+ HTTP_429_TOO_MANY_REQUESTS = 429
55
+ HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE = 431
56
+ HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS = 451
57
+ HTTP_500_INTERNAL_SERVER_ERROR = 500
58
+ HTTP_501_NOT_IMPLEMENTED = 501
59
+ HTTP_502_BAD_GATEWAY = 502
60
+ HTTP_503_SERVICE_UNAVAILABLE = 503
61
+ HTTP_504_GATEWAY_TIMEOUT = 504
62
+ HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505
63
+ HTTP_506_VARIANT_ALSO_NEGOTIATES = 506
64
+ HTTP_507_INSUFFICIENT_STORAGE = 507
65
+ HTTP_508_LOOP_DETECTED = 508
66
+ HTTP_509_BANDWIDTH_LIMIT_EXCEEDED = 509
67
+ HTTP_510_NOT_EXTENDED = 510
68
+ HTTP_511_NETWORK_AUTHENTICATION_REQUIRED = 511
69
+ end
70
+ end
data/lib/railerr.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'railerr/api_exceptions'
2
+ require_relative 'railerr/status'
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railerr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bernhard Niksch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.21'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.21'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-console
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ description: A declarative, fire and forget way to handle errors in a REST API
84
+ email:
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - lib/railerr.rb
90
+ - lib/railerr/api_exceptions.rb
91
+ - lib/railerr/status.rb
92
+ homepage:
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.7.6
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.4.10
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: RESTful API error handler
115
+ test_files: []