Skip to content

Commit

Permalink
chore: Improve Error handling, consistent logging and sentry/ rollbar
Browse files Browse the repository at this point in the history
Imrpoves debugging experience
  • Loading branch information
bonflintstone committed Aug 29, 2024
1 parent 6ca2cec commit f4a885d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.2.0
- `[ENHANCEMENT]` better error handling, more logging and sentry/ rollbar tracking

## 2.1.1
- `[FIX]` correct broken ruby import hierarchy. This was broken in Version `2.0`
- `[FIX]` add http status 500 as swagger responses
Expand Down
6 changes: 4 additions & 2 deletions box/apis/v2/accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ class Accounts < Grape::API
message: "Account created successfully. Please fetch INI letter, sign it, and submit it to your bank",
account: Entities::V2::Account.represent(account)
}
rescue BusinessProcesses::NewAccount::EbicsError => _ex
rescue BusinessProcesses::NewAccount::EbicsError => exception
log_error(exception)
error!({message: "Failed to setup ebics_user with your bank. Make sure your data is valid and retry!"}, 412)
rescue => _ex
rescue => exception
log_error(exception)
error!({message: "Failed to create account"}, 400)
end

Expand Down
5 changes: 2 additions & 3 deletions box/apis/v2/api_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ class Message < Grape::Entity
version "v2", using: :header, vendor: "ebicsbox"
format :json
helpers Helpers::Pagination
helpers Helpers::ErrorHandler

rescue_from :all do |exception|
Sentry.capture_exception(exception) if ENV["SENTRY_DSN"]
Rollbar.error(exception) if ENV["ROLLBAR_ACCESS_TOKEN"]
Box.logger.error(exception)
log_error(exception)
error!({error: "Internal server error"}, 500, {"Content-Type" => "application/json"})
end

Expand Down
4 changes: 2 additions & 2 deletions box/apis/v2/management/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class Organizations < Grape::API
organization.add_user(declared(params)[:user].merge(admin: true))
present organization, with: Entities::V2::Organization
end
rescue => ex
Box.logger.error("[Registration] #{ex.message}")
rescue => exception
log_error(exception, logger_prefix: "[Registration]")
error!({message: "Failed to create organization!"}, 400)
end
end
Expand Down
13 changes: 13 additions & 0 deletions box/helpers/error_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Box
module Helpers
module ErrorHandler
def log_error(exception, logger_prefix: "generic")
Sentry.capture_exception(exception) if ENV["SENTRY_DSN"]
Rollbar.error(exception) if ENV["ROLLBAR_ACCESS_TOKEN"]
Box.logger.error("[#{logger_prefix}] #{exception.class} :: \"#{exception.message}\"")
end
end
end
end

0 comments on commit f4a885d

Please sign in to comment.