Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.

Commit b6e6597

Browse files
Bonflintstonejanz93
andcommitted
chore: Improve Error handling, consistent logging and sentry/ rollbar
Improves debugging experience Co-authored-by: Jan von Magnus <jan.vonmagnus@railslove.com>
1 parent 6ca2cec commit b6e6597

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 2.2.0
4+
- `[ENHANCEMENT]` better error handling, more logging and sentry/ rollbar tracking
5+
36
## 2.1.1
47
- `[FIX]` correct broken ruby import hierarchy. This was broken in Version `2.0`
58
- `[FIX]` add http status 500 as swagger responses

box/apis/v2/accounts.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ class Accounts < Grape::API
7070
message: "Account created successfully. Please fetch INI letter, sign it, and submit it to your bank",
7171
account: Entities::V2::Account.represent(account)
7272
}
73-
rescue BusinessProcesses::NewAccount::EbicsError => _ex
73+
rescue BusinessProcesses::NewAccount::EbicsError => exception
74+
log_error(exception)
7475
error!({message: "Failed to setup ebics_user with your bank. Make sure your data is valid and retry!"}, 412)
75-
rescue => _ex
76+
rescue => exception
77+
log_error(exception)
7678
error!({message: "Failed to create account"}, 400)
7779
end
7880

box/apis/v2/api_endpoint.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "active_support/concern"
44

55
require_relative "../../helpers/pagination"
6+
require_relative "../../helpers/error_handler"
67

78
module Box
89
module Apis
@@ -30,11 +31,10 @@ class Message < Grape::Entity
3031
version "v2", using: :header, vendor: "ebicsbox"
3132
format :json
3233
helpers Helpers::Pagination
34+
helpers Helpers::ErrorHandler
3335

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

box/apis/v2/management/organizations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class Organizations < Grape::API
5454
organization.add_user(declared(params)[:user].merge(admin: true))
5555
present organization, with: Entities::V2::Organization
5656
end
57-
rescue => ex
58-
Box.logger.error("[Registration] #{ex.message}")
57+
rescue => exception
58+
log_error(exception, logger_prefix: "[Registration]")
5959
error!({message: "Failed to create organization!"}, 400)
6060
end
6161
end

box/helpers/error_handler.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module Box
4+
module Helpers
5+
module ErrorHandler
6+
def log_error(exception, logger_prefix: "generic")
7+
Sentry.capture_exception(exception) if ENV["SENTRY_DSN"]
8+
Rollbar.error(exception) if ENV["ROLLBAR_ACCESS_TOKEN"]
9+
Box.logger.error("[#{logger_prefix}] #{exception.class} :: \"#{exception.message}\"")
10+
end
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)