add custom exceptions handling controller

This commit is contained in:
Pete Matsyburka
2023-11-22 01:41:39 +02:00
parent f2c6bb1c3d
commit 542a443fb8
5 changed files with 37 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# frozen_string_literal: true
class ErrorsController < ActionController::Base
ENTERPRISE_FEATURE_MESSAGE =
'This feature is available in Enterprise Edition: https://www.docuseal.co/pricing'
ENTERPRISE_PATHS = [
'/templates/html',
'/api/templates/html',
'/templates/pdf',
'/api/templates/pdf'
].freeze
def show
if request.original_fullpath.in?(ENTERPRISE_PATHS)
return render json: { status: 404, message: ENTERPRISE_FEATURE_MESSAGE }, status: :not_found
end
respond_to do |f|
f.json do
render json: { status: error_status_code }, status: error_status_code
end
f.html { render error_status_code.to_s, status: error_status_code }
end
end
private
def error_status_code
@error_status_code ||=
ActionDispatch::ExceptionWrapper.new(request.env,
request.env['action_dispatch.exception']).status_code
end
end
+66
View File
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.error-page {
background-color: #FAF7F4;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
.error-page h1 {
font-weight: 700;
font-size: 3em;
color: #291434;
margin: 0 0 0.1em;
}
.error-page h2 {
font-weight: 700;
font-size: 10em;
color: #3BBFF7;
margin: 0 0 0.1em;
}
.error-page h3 {
font-weight: 600;
font-size: 1.75em;
color: #291434;
margin: 0.5em 0;
}
.error-page a.btn {
display: inline-block;
width: auto;
background-color: #291434;
padding: 1em 1.5em;
border-radius: 25px;
color: #ffffff;
text-decoration: none;
margin: 1em 0;
text-transform: uppercase;
}
.error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 6em auto 0;
}
</style>
</head>
<body class="error-page">
<div class="dialog">
<div>
<h1>DocuSeal</h1>
<h2>404</h2>
<h3>Sorry, we couldn't find this page.</h3>
</div>
<a rel="noopener noreferrer" href="/" class="btn">Back to homepage</a>
</div>
</body>
</html>
+66
View File
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>The change you wanted was rejected (422)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.error-page {
background-color: #FAF7F4;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
.error-page h1 {
font-weight: 700;
font-size: 3em;
color: #291434;
margin: 0 0 0.1em;
}
.error-page h2 {
font-weight: 700;
font-size: 10em;
color: #FABE22;
margin: 0 0 0.1em;
}
.error-page h3 {
font-weight: 600;
font-size: 1.75em;
color: #291434;
margin: 0.5em 0;
}
.error-page a.btn {
display: inline-block;
width: auto;
background-color: #291434;
padding: 1em 1.5em;
border-radius: 25px;
color: #ffffff;
text-decoration: none;
margin: 1em 0;
text-transform: uppercase;
}
.error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 6em auto 0;
}
</style>
</head>
<body class="error-page">
<div class="dialog">
<div>
<h1>DocuSeal</h1>
<h2>422</h2>
<h3>You're not allowed to access this page</h3>
</div>
<a rel="noopener noreferrer" href="/" class="btn">Back to homepage</a>
</div>
</body>
</html>
+66
View File
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.error-page {
background-color: #FAF7F4;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
.error-page h1 {
font-weight: 700;
font-size: 3em;
color: #291434;
margin: 0 0 0.1em;
}
.error-page h2 {
font-weight: 700;
font-size: 10em;
color: #F97272;
margin: 0 0 0.1em;
}
.error-page h3 {
font-weight: 600;
font-size: 1.75em;
color: #291434;
margin: 0.5em 0;
}
.error-page a.btn {
display: inline-block;
width: auto;
background-color: #291434;
padding: 1em 1.5em;
border-radius: 25px;
color: #ffffff;
text-decoration: none;
margin: 1em 0;
text-transform: uppercase;
}
.error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 6em auto 0;
}
</style>
</head>
<body class="error-page">
<div class="dialog">
<div>
<h1>DocuSeal</h1>
<h2>500</h2>
<h3>We're sorry, but something went wrong</h3>
</div>
<a rel="noopener noreferrer" href="/" class="btn">Back to homepage</a>
</div>
</body>
</html>