Skip to content

Commit

Permalink
Stringify error status
Browse files Browse the repository at this point in the history
Resolves #30
  • Loading branch information
swilgosz committed Oct 5, 2022
1 parent 6fb2724 commit 6c49d38
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/jsonapi_errors_handler/errors/invalid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(errors: {})
def serializable_hash
errors.reduce([]) do |r, (att, msg)|
r << {
status: status,
status: status.to_s,
title: title,
detail: msg,
source: { pointer: "/data/attributes/#{att}" }
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi_errors_handler/errors/standard_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(

def serializable_hash
{
status: status,
status: status.to_s,
title: title,
detail: detail,
source: source
Expand Down
8 changes: 4 additions & 4 deletions spec/error_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
STRING
expect(result[:errors]).to eq [
{
status: 500,
status: '500',
title: 'Something went wrong',
detail: message,
source: {}
Expand All @@ -33,13 +33,13 @@
result = subject.to_h
expect(result[:errors]).to eq [
{
status: 422,
status: '422',
title: 'Invalid request',
detail: "can't be blank",
source: { pointer: '/data/attributes/name' }
},
{
status: 422,
status: '422',
title: 'Invalid request',
detail: "can't be blank",
source: { pointer: '/data/attributes/password' }
Expand All @@ -56,7 +56,7 @@
{
'errors': [
{
'status': 500,
'status': '500',
'title': 'Something went wrong',
'detail': message,
'source': {}
Expand Down
6 changes: 3 additions & 3 deletions spec/jsonapi_errors_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def log_error(_error); end
{
detail: 'You have no rights to access this resource',
source: { 'pointer' => '/request/headers/authorization' },
status: 403,
status: '403',
title: 'Forbidden request'
}
],
Expand Down Expand Up @@ -76,7 +76,7 @@ def log_error(_error); end
{
detail: "We've encountered unexpected error, but our developers had been already notified about it",
source: {},
status: 500,
status: '500',
title: 'Something went wrong'
}
],
Expand Down Expand Up @@ -138,7 +138,7 @@ def log_error(_error); end
{
detail: 'You have no rights to access this resource',
source: { 'pointer' => '/request/headers/authorization' },
status: 403,
status: '403',
title: 'Forbidden request'
}
],
Expand Down

0 comments on commit 6c49d38

Please sign in to comment.