Skip to content

Commit a88b7e7

Browse files
committed
Merge pull request #524 from iamvery/exception-response
Include exception message and backtrace in response
2 parents e032f83 + 81c05a1 commit a88b7e7

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/jsonapi/error.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module JSONAPI
22
class Error
3-
attr_accessor :title, :detail, :id, :href, :code, :source, :links, :status
3+
attr_accessor :title, :detail, :id, :href, :code, :source, :links, :status, :meta
44

55
def initialize(options = {})
66
@title = options[:title]
@@ -16,6 +16,7 @@ def initialize(options = {})
1616
@links = options[:links]
1717

1818
@status = Rack::Utils::SYMBOL_TO_STATUS_CODE[options[:status]].to_s
19+
@meta = options[:meta]
1920
end
2021
end
2122

lib/jsonapi/exceptions.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ def initialize(exception)
1010
end
1111

1212
def errors
13+
unless Rails.env.prod?
14+
meta = Hash.new
15+
meta[:exception] = exception.message
16+
meta[:backtrace] = exception.backtrace
17+
end
18+
1319
[JSONAPI::Error.new(code: JSONAPI::INTERNAL_SERVER_ERROR,
1420
status: :internal_server_error,
1521
title: 'Internal Server Error',
16-
detail: 'Internal Server Error')]
22+
detail: 'Internal Server Error',
23+
meta: meta)]
1724
end
1825
end
1926

0 commit comments

Comments
 (0)