Skip to content

Commit

Permalink
better graphql error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfranzen committed Sep 12, 2020
1 parent b8202bc commit edcec4e
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def execute
)
render json: result
rescue StandardError => e
raise e unless Rails.env.development?

handle_error_in_development e
handle_error e
end

private
Expand All @@ -47,15 +45,14 @@ def ensure_hash(ambiguous_param)
end
end

def handle_error_in_development(err)
def handle_error(err)
logger.error err.message
logger.error err.backtrace.join("\n")

render json: {
error: {
message: err.message,
backtrace: err.backtrace
},
errors: [
{ message: err.message }
],
data: {}
}, status: 500
end
Expand Down

0 comments on commit edcec4e

Please sign in to comment.