@@ -126,3 +126,119 @@ Content-Type: application/vnd.api+json
126
126
for readability. In practice, these characters must be percent-encoded, as
127
127
noted in the base specification.
128
128
129
+ ## Error Objects
130
+
131
+ Examples of how [ example objects] ( http://jsonapi.org/format/#error-objects ) work.
132
+
133
+ ### Responses to failed resource creation:
134
+
135
+ Response with one error object:
136
+
137
+ ``` http
138
+ HTTP/1.1 422 Unprocessable Entity
139
+ Content-Type: application/vnd.api+json
140
+
141
+ {
142
+ "errors": [
143
+ {
144
+ "source": { "pointer": "data/attributes/first_name" },
145
+ "detail": "is too short"
146
+ }
147
+ ]
148
+ }
149
+ ```
150
+
151
+ Response with status:
152
+
153
+ ``` http
154
+ HTTP/1.1 422 Unprocessable Entity
155
+ Content-Type: application/vnd.api+json
156
+
157
+ {
158
+ "errors": [
159
+ {
160
+ "source": { "pointer": "data/attributes/first_name" },
161
+ "detail": "is too short"
162
+ },
163
+ {
164
+ "status": "422",
165
+ }
166
+ ]
167
+ }
168
+ ```
169
+ The only uniqueness constraint on error objects in a response is the ` id ` field.
170
+ Multiple errors on the same attribute may be described by an error object
171
+ for each error.
172
+
173
+ Multiple errors on ` first_name ` attribute:
174
+
175
+ ``` http
176
+ HTTP/1.1 422 Unprocessable Entity
177
+ Content-Type: application/vnd.api+json
178
+
179
+ {
180
+ "errors": [
181
+ {
182
+ "source": { "pointer": "data/attributes/first_name" },
183
+ "detail": "is too short"
184
+ },
185
+ {
186
+ "source": { "pointer": "data/attributes/first_name" },
187
+ "detail": "must contain an emoji"
188
+ }
189
+ ]
190
+ }
191
+ ```
192
+
193
+ If the API docs specified:
194
+
195
+ > | Error Code | Title |
196
+ > | ------------| ----------------------|
197
+ > | 123 | "too short" |
198
+ > | 124 | "emoji missing" |
199
+
200
+ Multiple errors on ` first_name ` attribute, with error "code":
201
+
202
+ ``` http
203
+ HTTP/1.1 422 Unprocessable Entity
204
+ Content-Type: application/vnd.api+json
205
+
206
+ {
207
+ "errors": [
208
+ {
209
+ "code": "123",
210
+ "source": { "pointer": "data/attributes/first_name" },
211
+ "detail": "is too short"
212
+ },
213
+ {
214
+ "code": "124",
215
+ "source": { "pointer": "data/attributes/first_name" },
216
+ "detail": "must contain an emoji"
217
+ }
218
+ ]
219
+ }
220
+ ```
221
+
222
+ Multiple errors on ` first_name ` attribute, with error code, and "title":
223
+
224
+ ``` http
225
+ HTTP/1.1 422 Unprocessable Entity
226
+ Content-Type: application/vnd.api+json
227
+
228
+ {
229
+ "errors": [
230
+ {
231
+ "code": "123",
232
+ "title": "too short",
233
+ "source": { "pointer": "data/attributes/first_name" },
234
+ "detail": "is too short"
235
+ },
236
+ {
237
+ "code": "124",
238
+ "title": "emoji missing",
239
+ "source": { "pointer": "data/attributes/first_name" },
240
+ "detail": "must contain an emoji"
241
+ }
242
+ ]
243
+ }
244
+ ```
0 commit comments