Skip to content

Commit 7a105a5

Browse files
committed
Added code to error attributes. Closes #95
1 parent b1c2080 commit 7a105a5

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/jsonapi/error_serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ErrorSerializer
88
set_type :error
99

1010
# Object/Hash attribute helpers.
11-
[:status, :source, :title, :detail].each do |attr_name|
11+
[:status, :source, :title, :detail, :code].each do |attr_name|
1212
attribute attr_name do |object|
1313
object.try(attr_name) || object.try(:fetch, attr_name, nil)
1414
end

spec/errors_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@
3232
it do
3333
expect(response).to have_http_status(:unprocessable_entity)
3434
expect(response_json['errors'].size).to eq(1)
35+
36+
expect(response_json['errors'].first.keys)
37+
.to contain_exactly('status', 'source', 'title', 'detail', 'code')
38+
3539
expect(response_json['errors'][0]['status']).to eq('422')
3640
expect(response_json['errors'][0]['title'])
3741
.to eq(Rack::Utils::HTTP_STATUS_CODES[422])
3842
expect(response_json['errors'][0]['source']).to eq('pointer' => '')
3943
expect(response_json['errors'][0]['detail']).to be_nil
44+
expect(response_json['errors'][0]['code']).to be_nil
4045
end
4146
end
4247

0 commit comments

Comments
 (0)