jsonapi-utils 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/lib/jsonapi/utils.rb +10 -8
- data/lib/jsonapi/utils/exceptions.rb +18 -32
- data/lib/jsonapi/utils/version.rb +1 -1
- 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: 787dd4e20ecfc0d81ad5221eee77897c4baece34
|
4
|
+
data.tar.gz: 8fb454390a928f5af72ad95334448fc5bac631b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f38a040d3b83edc9f62cd13cd6be0554af7e6d9dd4261cb38d11617affc01c900d0c7f75bf7def9c5420ba9b234440fe5d8ffb570e9e2a07cafb0e661cc91e8d
|
7
|
+
data.tar.gz: 772676ea003068c1c5b763e57be30b73266f96d9b5ba8f137202f77612a557196c828a661d60ce334adba1a4ef32b4c5856d6be7c1f185bcb9deac24715e307c
|
data/lib/jsonapi/utils.rb
CHANGED
@@ -16,24 +16,26 @@ module JSONAPI
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def jsonapi_render_errors(exception)
|
20
|
+
error = jsonapi_format_errors(exception)
|
21
|
+
render json: { errors: error.errors }, status: error.code
|
22
|
+
end
|
23
|
+
|
24
|
+
def jsonapi_format_errors(exception)
|
25
|
+
JSONAPI::ErrorsOperationResult.new(exception.errors[0].code, exception.errors)
|
21
26
|
end
|
22
27
|
|
23
28
|
def jsonapi_render_internal_server_error
|
24
|
-
|
25
|
-
render json: jsonapi_errors(errors), status: 500
|
29
|
+
jsonapi_render_errors(::JSONAPI::Utils::Exceptions::InternalServerError.new)
|
26
30
|
end
|
27
31
|
|
28
32
|
def jsonapi_render_bad_request
|
29
|
-
|
30
|
-
render json: jsonapi_errors(errors), status: 400
|
33
|
+
jsonapi_render_errors(::JSONAPI::Utils::Exceptions::BadRequest.new)
|
31
34
|
end
|
32
35
|
|
33
36
|
def jsonapi_render_not_found
|
34
37
|
id = extract_ids(@request.params)
|
35
|
-
|
36
|
-
render json: jsonapi_errors(exception), status: 404
|
38
|
+
jsonapi_render_errors(JSONAPI::Exceptions::RecordNotFound.new(id))
|
37
39
|
end
|
38
40
|
|
39
41
|
def jsonapi_render_not_found_with_null
|
@@ -1,40 +1,26 @@
|
|
1
1
|
require 'jsonapi/utils/version'
|
2
2
|
|
3
|
-
module JSONAPI
|
4
|
-
|
5
|
-
|
6
|
-
class BadRequest < ::JSONAPI::Exceptions::Error
|
7
|
-
def code; 400 end
|
3
|
+
module JSONAPI::Utils::Exceptions
|
4
|
+
class BadRequest < ::JSONAPI::Exceptions::Error
|
5
|
+
def code; 400 end
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
class NotFoundError < ::JSONAPI::Exceptions::Error
|
18
|
-
def code; 404 end
|
19
|
-
|
20
|
-
def errors
|
21
|
-
[JSONAPI::Error.new(code: 404,
|
22
|
-
status: :not_found,
|
23
|
-
title: 'Not Found',
|
24
|
-
detail: 'The requested resource was not found.')]
|
25
|
-
end
|
26
|
-
end
|
7
|
+
def errors
|
8
|
+
[JSONAPI::Error.new(code: 400,
|
9
|
+
status: :bad_request,
|
10
|
+
title: 'Bad Request',
|
11
|
+
detail: 'This request is not supported.')]
|
12
|
+
end
|
13
|
+
end
|
27
14
|
|
28
|
-
|
29
|
-
|
15
|
+
class InternalServerError < ::JSONAPI::Exceptions::Error
|
16
|
+
def code; 500 end
|
30
17
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
18
|
+
def errors
|
19
|
+
[JSONAPI::Error.new(code: 500,
|
20
|
+
status: :internal_server_error,
|
21
|
+
title: 'Internal Server Error',
|
22
|
+
detail: 'An internal error ocurred while processing the request.')]
|
38
23
|
end
|
39
24
|
end
|
40
25
|
end
|
26
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Guedes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-10-
|
12
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|