Skip to content

Commit

Permalink
Resolves driggl#30 Make error object's status a string
Browse files Browse the repository at this point in the history
force string as base

fix specs
  • Loading branch information
tibomogul committed Jan 12, 2021
1 parent 9b4e64e commit 1546b3b
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/jsonapi_errors_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def handle_unexpected_error(error)
end

def render_error(error)
render json: ::JsonapiErrorsHandler::ErrorSerializer.new(error), status: error.status
render json: ::JsonapiErrorsHandler::ErrorSerializer.new(error), status: error.status.to_i
end

def self.configure(&block)
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi_errors_handler/errors/forbidden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Forbidden < ::JsonapiErrorsHandler::Errors::StandardError
def initialize(message: nil)
super(
title: 'Forbidden request',
status: 403,
status: '403',
detail: message || 'You have no rights to access this resource',
source: { pointer: '/request/headers/authorization' }
)
Expand Down
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 @@ -7,7 +7,7 @@ module Errors
class Invalid < ::JsonapiErrorsHandler::Errors::StandardError
def initialize(errors: {})
@errors = errors
@status = 422
@status = '422'
@title = 'Invalid request'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi_errors_handler/errors/not_found.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NotFound < ::JsonapiErrorsHandler::Errors::StandardError
def initialize(message: nil)
super(
title: 'Record not Found',
status: 404,
status: '404',
detail: message || 'We could not find the object you were looking for.',
source: { pointer: '/request/url/:id' }
)
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 @@ -14,7 +14,7 @@ def initialize(
@title = title || 'Something went wrong'
@detail = detail || message
@detail ||= "We've encountered unexpected error, but our developers had been already notified about it" # rubocop:disable Metrics/LineLength
@status = status || 500
@status = status || '500'
@source = KeysStringifier.call(source)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi_errors_handler/errors/unauthorized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Unauthorized < ::JsonapiErrorsHandler::Errors::StandardError
def initialize(message: nil)
super(
title: 'Unauthorized',
status: 401,
status: '401',
detail: message || 'You need to login to authorize this request.',
source: { pointer: '/request/headers/authorization' }
)
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 @@ -43,7 +43,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 @@ -74,7 +74,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 @@ -116,7 +116,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 1546b3b

Please sign in to comment.