better error handling (#677)

* swap honeybadger for sentry

* better error pages
This commit is contained in:
Echo
2025-12-01 12:33:01 -05:00
committed by GitHub
parent 0260a16c6c
commit 64fc0f1f1b
18 changed files with 117 additions and 729 deletions

View File

@@ -41,7 +41,7 @@ module Api
existing:
}
rescue => e
Honeybadger.notify(e, context: { slack_uid: slack_uid, email: email, params: params.to_unsafe_h })
Sentry.capture_exception(e, extra: { slack_uid: slack_uid, email: email, params: params.to_unsafe_h })
render json: { error: "internal error creating magic link" }, status: 500
end
end

View File

@@ -1,6 +1,6 @@
class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit
before_action :honeybadger_context, if: :current_user
before_action :sentry_context, if: :current_user
before_action :initialize_cache_counters
before_action :try_rack_mini_profiler_enable
before_action :track_request
@@ -25,11 +25,14 @@ class ApplicationController < ActionController::Base
@activities = PublicActivity::Activity.limit(25).order(created_at: :desc).includes(:owner, :trackable)
end
def honeybadger_context
Honeybadger.context(
user_id: current_user.id,
def sentry_context
Sentry.set_user(
id: current_user.id,
username: current_user.username
)
Sentry.set_extras(
user_agent: request.user_agent,
ip_address: request.headers["CF-Connecting-IP"] || request.remote_ip,
ip_address: request.headers["CF-Connecting-IP"] || request.remote_ip
)
end

View File

@@ -0,0 +1,43 @@
# frozen_string_literal: true
class ErrorsController < ApplicationController
skip_before_action :verify_authenticity_token
def bad_request
@status_code = 400
@title = "Bad Request"
@message = "The server cannot process your request due to invalid syntax."
render_error
end
def not_found
@status_code = 404
@title = "Page Not Found"
@message = "The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved."
render_error
end
def unprocessable_entity
@status_code = 422
@title = "Unprocessable Content"
@message = "The request was well-formed but unable to be followed due to semantic errors."
render_error
end
def internal_server_error
@status_code = 500
@title = "Internal Server Error"
@message = "Something went wrong on our end, but we are looking into it!"
render_error
end
private
def render_error
render "errors/show", status: @status_code, layout: error_layout
end
def error_layout
"errors"
end
end

View File

@@ -12,8 +12,8 @@ class SessionsController < ApplicationController
if params[:error].present?
Rails.logger.error "Slack OAuth error: #{params[:error]}"
uuid = Honeybadger.notify("Slack OAuth error: #{params[:error]}")
redirect_to root_path, alert: "Failed to authenticate with Slack. Error ID: #{uuid}"
Sentry.capture_message("Slack OAuth error: #{params[:error]}")
redirect_to root_path, alert: "Failed to authenticate with Slack. Error ID: #{Sentry.last_event_id}"
return
end
@@ -67,8 +67,8 @@ class SessionsController < ApplicationController
if params[:error].present?
Rails.logger.error "GitHub OAuth error: #{params[:error]}"
uuid = Honeybadger.notify("GitHub OAuth error: #{params[:error]}")
redirect_to my_settings_path, alert: "Failed to authenticate with GitHub. Error ID: #{uuid}"
Sentry.capture_message("GitHub OAuth error: #{params[:error]}")
redirect_to my_settings_path, alert: "Failed to authenticate with GitHub. Error ID: #{Sentry.last_event_id}"
return
end

View File

@@ -0,0 +1,22 @@
<div class="flex flex-col items-center justify-center text-center p-8 max-w-3xl">
<div class="mb-6">
<div class="text-8xl font-bold text-primary mb-2"><%= @status_code %></div>
<h1 class="text-3xl font-bold text-white mb-4"><%= @title %></h1>
</div>
<div class="bg-dark rounded-xl p-6 mb-6 border border-darkless">
<p class="text-muted text-lg"><%= @message %></p>
</div>
<div class="flex flex-col sm:flex-row gap-4">
<%= link_to "Go Home", root_path, class: "px-6 py-3 bg-primary text-white rounded-lg font-medium hover:bg-red-600 transition-colors" %>
<button onclick="history.back()" class="px-6 py-3 bg-dark text-white rounded-lg font-medium hover:bg-darkless transition-colors border border-darkless cursor-pointer">
Go Back
</button>
</div>
<p class="mt-8 text-sm text-muted">
If this problem persists, please contact us on
<%= link_to "Slack", "https://hackclub.slack.com", class: "text-primary hover:underline", target: "_blank" %>.
</p>
</div>

View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html class="<%= Rails.env == "production" ? "production" : "development" %>" data-theme="dark">
<head>
<title><%= @title %> - Hackatime</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="color-scheme" content="dark">
<meta name="robots" content="noindex, nofollow">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= favicon_link_tag asset_path('favicon.png'), type: 'image/png' %>
<%= stylesheet_link_tag :app %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
</head>
<body class="bg-darker">
<div class="flex min-h-screen items-center justify-center mx-auto">
<%= yield %>
</div>
</body>
</html>