json_error_serializer 0.3.0 → 0.3.1
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 +29 -10
- data/lib/json_error_serializer/extenders/controller.rb +4 -0
- data/lib/json_error_serializer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 681c9a5d4493d5d33ed9a89421a8da50f275d01a
|
4
|
+
data.tar.gz: 4a2d68f44b3d46a26b3048700ead9195f1644c1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f27476f66e53b77544e40e7fcc5e7b04f82691788776ea88ba6a70e6d2b4cb4f65e20005431805d198aa8d159232b7352d4fe18462fb0ef612255047d4a74ac7
|
7
|
+
data.tar.gz: d80dbccf480bdb069efbd82bfb1a8d7fdb21305fee6f6bde88545a0f2659ecfc9aa1cbc916a78e9ef7a4b891e175a0e3c92a489cd4660a907d8becb73b003d1a
|
data/README.md
CHANGED
@@ -1,38 +1,57 @@
|
|
1
1
|
# JsonErrorSerializer
|
2
2
|
|
3
|
-
|
3
|
+
This gem provides a simple way to respond API errors messages with correct HTTP responces from Ruby On Rails applications.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem '
|
10
|
+
gem 'json_error_serializer'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
$ bundle
|
15
|
+
$ bundle install
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install
|
19
|
+
$ gem install json_error_serializer
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
In your controller:
|
24
|
+
```ruby
|
25
|
+
respond_404
|
26
|
+
```
|
24
27
|
|
25
|
-
|
28
|
+
```ruby
|
29
|
+
respond_404('User not found')
|
30
|
+
```
|
26
31
|
|
27
|
-
|
32
|
+
Result:
|
33
|
+
HTTP 404 (Not found)
|
34
|
+
```json
|
35
|
+
{
|
36
|
+
"status": "404",
|
37
|
+
"message": "Not found"
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
```json
|
42
|
+
{
|
43
|
+
"status": "404",
|
44
|
+
"message": "User not found"
|
45
|
+
}
|
46
|
+
```
|
28
47
|
|
29
|
-
|
48
|
+
Available methods refer to the [wiki](https://github.com/Strollager/error_json_serializer/wiki)
|
30
49
|
|
31
50
|
## Contributing
|
32
51
|
|
33
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Strollager/error_json_serializer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
53
|
|
35
54
|
|
36
55
|
## License
|
37
56
|
|
38
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
57
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -3,6 +3,10 @@ module JsonErrorSerializer
|
|
3
3
|
|
4
4
|
module Controller
|
5
5
|
|
6
|
+
def validate_errors_serialize(errors)
|
7
|
+
render json: JsonErrorSerializer::Extenders::Serialize.serialize(errors), status: :conflict
|
8
|
+
end
|
9
|
+
|
6
10
|
def respond_200(message = nil)
|
7
11
|
render json: JsonErrorSerializer::Extenders::Serialize._200(message), status: :ok
|
8
12
|
end
|