Skip to content

Commit e4c7a5a

Browse files
committed
Custom 404, 500, and 403 error pages
Summary: * Templates in `resources/views/errors/` for error pages * Partial for error page content as well * Translation strings for title and body of each error code * Updated tests to search for status code on relevant pages Misc: * Moved the `LoadPages` middleware so it runs on all requests Resolves T264 Test Plan: * Go to a URL that doesn't exists, check 404 page * Go to an unauthorized URL and check 403 page * Put in an `abort(500)` somewhere to check 500 page Reviewers: doshitan Reviewed By: doshitan Maniphest Tasks: T264 Differential Revision: https://phabricator.opengovfoundation.org/D155
1 parent 7170fcb commit e4c7a5a

File tree

12 files changed

+48
-9
lines changed

12 files changed

+48
-9
lines changed

app/Http/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Kernel extends HttpKernel
1515
*/
1616
protected $middleware = [
1717
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
18+
\App\Http\Middleware\LoadPages::class,
1819
];
1920

2021
/**
@@ -28,7 +29,6 @@ class Kernel extends HttpKernel
2829
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
2930
\Illuminate\Session\Middleware\StartSession::class,
3031
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
31-
\App\Http\Middleware\LoadPages::class,
3232
\App\Http\Middleware\VerifyCsrfToken::class,
3333
\Illuminate\Routing\Middleware\SubstituteBindings::class,
3434
],

resources/lang/en/messages.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,4 +437,19 @@
437437
'google_analytics_property_id_help' => 'The UA-XXXXX-Y string identifying which Google Analytics property you wish to track traffic against',
438438
],
439439
],
440+
441+
'error' => [
442+
'404' => [
443+
'title' => 'Not Found (404)',
444+
'body' => 'Whatever you were looking for was not found. Try going back and giving it another shot.',
445+
],
446+
'403' => [
447+
'title' => 'Not Authorized (403)',
448+
'body' => 'You are not authorized to perform this action, please go back.',
449+
],
450+
'500' => [
451+
'title' => 'Something went wrong (500)',
452+
'body' => 'There was a problem in our system, we apologize for the inconvenience.',
453+
],
454+
],
440455
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@extends('layouts.app')
2+
3+
@section('pageTitle', trans('messages.error.403.title'))
4+
5+
@section('content')
6+
@include('errors.partials.error_content', ['status' => '403'])
7+
@endsection
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@extends('layouts.app')
2+
3+
@section('pageTitle', trans('messages.error.404.title'))
4+
5+
@section('content')
6+
@include('errors.partials.error_content', ['status' => '404'])
7+
@endsection
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@extends('layouts.app')
2+
3+
@section('pageTitle', trans('messages.error.500.title'))
4+
5+
@section('content')
6+
@include('errors.partials.error_content', ['status' => '500'])
7+
@endsection
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>@lang('messages.error.' . $status . '.title')</h1>
2+
<hr>
3+
<p class="lead">@lang('messages.error.' . $status . '.body')</p>

tests/Browser/AdminTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function assertNonAdminsDenied($browser, $page)
3232
->loginAs($this->user)
3333
->visit($page)
3434
// 403 status
35-
->assertSee('Whoops, looks like something went wrong')
35+
->assertSee('403')
3636
;
3737
}
3838
}

tests/Browser/Document/Manage/CommentsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testSponsorCannotEditOtherDocument()
7070
->loginAs($this->sponsorOwner)
7171
->visit(new CommentsPage($otherDocument))
7272
// 403 status
73-
->assertSee('Whoops, looks like something went wrong')
73+
->assertSee('403')
7474
;
7575
});
7676
}

tests/Browser/Document/Manage/SettingsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testSponsorCannotEditOtherDocument()
7575
->loginAs($this->sponsorOwner)
7676
->visit(new SettingsPage($otherDocument))
7777
// 403 status
78-
->assertSee('Whoops, looks like something went wrong')
78+
->assertSee('403')
7979
;
8080
});
8181
}

tests/Browser/DocumentPageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function testCantViewUnpublishedDocument()
175175
$this->browse(function ($browser) {
176176
$browser
177177
->visit($this->page)
178-
->assertSee('This action is unauthorized')
178+
->assertSee('403')
179179
;
180180
});
181181
}

0 commit comments

Comments
 (0)