feat: Add error handling for relay server response and custom error pages

This commit includes the following changes:
- Added error handling in the election views to check if the relay server responds with an error message
- Included custom error pages for different HTTP status codes (401, 402, 403, 404, 419, 429, 500, 503)
- Created a new layout for the error pages
This commit is contained in:
fsociety
2024-09-29 19:51:13 +02:00
parent 5ba881dd60
commit 0dd577e9d5
12 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Unauthorized'))
@section('code', '401')
@section('message', __('Unauthorized'))

View File

@@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Payment Required'))
@section('code', '402')
@section('message', __('Payment Required'))

View File

@@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Forbidden'))
@section('code', '403')
@section('message', __($exception->getMessage() ?: 'Forbidden'))

View File

@@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Not Found'))
@section('code', '404')
@section('message', __('Not Found'))

View File

@@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Page Expired'))
@section('code', '419')
@section('message', __('Page Expired'))

View File

@@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Too Many Requests'))
@section('code', '429')
@section('message', __('Too Many Requests'))

View File

@@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Server Error'))
@section('code', '500')
@section('message', __($exception->getMessage() ?: 'Server Error'))

View File

@@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Service Unavailable'))
@section('code', '503')
@section('message', __('Service Unavailable'))

View File

@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@yield('title')</title>
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-weight: 100;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.content {
text-align: center;
}
.title {
font-size: 36px;
padding: 20px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title">
@yield('message')
</div>
</div>
</div>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -94,6 +94,11 @@ $loadEvents = function () {
$request = new Request($relaySet, $requestMessage);
$response = $request->send();
// Check for errors in the response
if (isset($response[config('services.relay')][0][0]) && $response[config('services.relay')][0][0] === 'ERROR') {
abort(500, 'Kann keine Events laden. Nostr Relay antwortet nicht.');
}
$this->events = collect($response[config('services.relay')])
->map(fn($event)
=> [

View File

@@ -134,6 +134,11 @@ $loadEvents = function () {
$request = new Request($relaySet, $requestMessage);
$response = $request->send();
// Check for errors in the response
if (isset($response[config('services.relay')][0][0]) && $response[config('services.relay')][0][0] === 'ERROR') {
abort(500, 'Kann keine Events laden. Nostr Relay antwortet nicht.');
}
$this->events = collect($response[config('services.relay')])
->map(fn($event)
=> [