You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/active_model_serializers/adapter/json_api/error.rb
+74-63Lines changed: 74 additions & 63 deletions
Original file line number
Diff line number
Diff line change
@@ -2,90 +2,101 @@ module ActiveModelSerializers
2
2
moduleAdapter
3
3
classJsonApi < Base
4
4
classError < Base
5
-
=begin
6
-
## http://jsonapi.org/format/#document-top-level
5
+
UnknownSourceTypeError=Class.new(ArgumentError)
6
+
# rubocop:disable Style/AsciiComments
7
+
# TODO: look into caching
7
8
8
-
A document MUST contain at least one of the following top-level members:
9
-
10
-
- data: the document's "primary data"
11
-
- errors: an array of error objects
12
-
- meta: a meta object that contains non-standard meta-information.
13
-
14
-
The members data and errors MUST NOT coexist in the same document.
15
-
16
-
## http://jsonapi.org/format/#error-objects
17
-
18
-
Error objects provide additional information about problems encountered while performing an operation. Error objects MUST be returned as an array keyed by errors in the top level of a JSON API document.
9
+
# definition:
10
+
# ☐ toplevel_errors array (required)
11
+
# ☑ toplevel_meta
12
+
# ☑ toplevel_jsonapi
13
+
defserializable_hash(*)
14
+
hash={}
15
+
# PR Please :)
16
+
# Jsonapi.add!(hash)
19
17
20
-
An error object MAY have the following members:
18
+
# Checking object since we're not using an ArraySerializer
19
+
ifserializer.object.respond_to?(:each)
20
+
hash[:errors]=collection_errors
21
+
else
22
+
hash[:errors]=Error.resource_errors(serializer)
23
+
end
24
+
hash
25
+
end
21
26
22
-
- id: a unique identifier for this particular occurrence of the problem.
23
-
- links: a links object containing the following members:
24
-
- about: a link that leads to further details about this particular occurrence of the problem.
25
-
- status: the HTTP status code applicable to this problem, expressed as a string value.
26
-
- code: an application-specific error code, expressed as a string value.
27
-
- title: a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
28
-
- detail: a human-readable explanation specific to this occurrence of the problem.
29
-
- source: an object containing references to the source of the error, optionally including any of the following members:
30
-
- pointer: a JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute].
31
-
- parameter: a string indicating which query parameter caused the error.
32
-
- meta: a meta object containing non-standard meta-information about the error.
0 commit comments