mirror of
https://github.com/standardebooks/web.git
synced 2025-07-05 14:20:29 -04:00
Use HTTP code enums instead of ints
This commit is contained in:
parent
3f822b85c3
commit
3050ab7219
28 changed files with 56 additions and 56 deletions
|
@ -34,13 +34,13 @@ class Template{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Emit403(): void{
|
public static function Emit403(): void{
|
||||||
http_response_code(403);
|
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||||
include(WEB_ROOT . '/403.php');
|
include(WEB_ROOT . '/403.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Emit404(): void{
|
public static function Emit404(): void{
|
||||||
http_response_code(404);
|
http_response_code(Enums\HttpCode::NotFound->value);
|
||||||
include(WEB_ROOT . '/404.php');
|
include(WEB_ROOT . '/404.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ try{
|
||||||
|
|
||||||
// We got here because an artwork update had errors and the user has to try again.
|
// We got here because an artwork update had errors and the user has to try again.
|
||||||
if($exception){
|
if($exception){
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
session_unset();
|
session_unset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ try{
|
||||||
|
|
||||||
// We got here because an artwork PATCH operation had errors and the user has to try again.
|
// We got here because an artwork PATCH operation had errors and the user has to try again.
|
||||||
if($exception){
|
if($exception){
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
|
|
||||||
// Before we overwrite the original artwork with our new one, restore the old status, because if the new status is 'approved' then it will hide the status form entirely, which will be confusing.
|
// Before we overwrite the original artwork with our new one, restore the old status, because if the new status is 'approved' then it will hide the status form entirely, which will be confusing.
|
||||||
$oldStatus = $artwork->Status;
|
$oldStatus = $artwork->Status;
|
||||||
|
|
|
@ -20,14 +20,14 @@ try{
|
||||||
|
|
||||||
// We got here because an artwork was successfully submitted.
|
// We got here because an artwork was successfully submitted.
|
||||||
if($isCreated){
|
if($isCreated){
|
||||||
http_response_code(201);
|
http_response_code(Enums\HttpCode::Created->value);
|
||||||
$artwork = null;
|
$artwork = null;
|
||||||
session_unset();
|
session_unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We got here because an artwork submission had errors and the user has to try again.
|
// We got here because an artwork submission had errors and the user has to try again.
|
||||||
if($exception){
|
if($exception){
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
session_unset();
|
session_unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ try{
|
||||||
$_SESSION['artwork'] = $artwork;
|
$_SESSION['artwork'] = $artwork;
|
||||||
$_SESSION['is-created'] = true;
|
$_SESSION['is-created'] = true;
|
||||||
|
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: /artworks/new');
|
header('Location: /artworks/new');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ try{
|
||||||
$_SESSION['artwork'] = $artwork;
|
$_SESSION['artwork'] = $artwork;
|
||||||
$_SESSION['is-saved'] = true;
|
$_SESSION['is-saved'] = true;
|
||||||
|
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: ' . $artwork->Url);
|
header('Location: ' . $artwork->Url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ try{
|
||||||
$_SESSION['artwork'] = $artwork;
|
$_SESSION['artwork'] = $artwork;
|
||||||
$_SESSION['is-saved'] = true;
|
$_SESSION['is-saved'] = true;
|
||||||
|
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: ' . $artwork->Url);
|
header('Location: ' . $artwork->Url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,6 @@ catch(Exceptions\InvalidArtworkException | Exceptions\InvalidArtworkTagException
|
||||||
$_SESSION['artwork'] = $artwork;
|
$_SESSION['artwork'] = $artwork;
|
||||||
$_SESSION['exception'] = $ex;
|
$_SESSION['exception'] = $ex;
|
||||||
|
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: ' . $exceptionRedirectUrl);
|
header('Location: ' . $exceptionRedirectUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ catch(Exceptions\LoginRequiredException){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidPermissionsException){
|
catch(Exceptions\InvalidPermissionsException){
|
||||||
http_response_code(403);
|
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidFileException){
|
catch(Exceptions\InvalidFileException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
|
|
|
@ -56,7 +56,7 @@ catch(Exceptions\EbookNotFoundException){
|
||||||
$ebook = Ebook::GetByIdentifierStartingWith($identifier);
|
$ebook = Ebook::GetByIdentifierStartingWith($identifier);
|
||||||
|
|
||||||
// Found, redirect.
|
// Found, redirect.
|
||||||
http_response_code(301);
|
http_response_code(Enums\HttpCode::MovedPermanently->value);
|
||||||
header('Location: ' . $ebook->Url);
|
header('Location: ' . $ebook->Url);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ catch(Exceptions\PageOutOfBoundsException){
|
||||||
}
|
}
|
||||||
catch(Exceptions\AppException $ex){
|
catch(Exceptions\AppException $ex){
|
||||||
// Something very unexpected happened, log and emit 500.
|
// Something very unexpected happened, log and emit 500.
|
||||||
http_response_code(500); // Internal server error.
|
http_response_code(Enums\HttpCode::InternalServerError->value); // Internal server error.
|
||||||
Log::WriteErrorLogEntry($ex);
|
Log::WriteErrorLogEntry($ex);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ try{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(\Exception){
|
catch(\Exception){
|
||||||
http_response_code(500);
|
http_response_code(Enums\HttpCode::InternalServerError->value);
|
||||||
include(WEB_ROOT . '/404.php');
|
include(WEB_ROOT . '/404.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,10 +98,10 @@ try{
|
||||||
}
|
}
|
||||||
catch(Exceptions\LoginRequiredException){
|
catch(Exceptions\LoginRequiredException){
|
||||||
header('WWW-Authenticate: Basic realm="Enter your Patrons Circle email address and leave the password empty."');
|
header('WWW-Authenticate: Basic realm="Enter your Patrons Circle email address and leave the password empty."');
|
||||||
http_response_code(401);
|
http_response_code(Enums\HttpCode::Unauthorized->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidPermissionsException){
|
catch(Exceptions\InvalidPermissionsException){
|
||||||
http_response_code(403);
|
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidFileException){
|
catch(Exceptions\InvalidFileException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
|
|
|
@ -11,7 +11,7 @@ try{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(\Exception){
|
catch(\Exception){
|
||||||
http_response_code(500);
|
http_response_code(Enums\HttpCode::InternalServerError->value);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"". SITE_URL . "/feeds/opds/style\" type=\"text/xsl\"?>\n");
|
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"". SITE_URL . "/feeds/opds/style\" type=\"text/xsl\"?>\n");
|
||||||
|
|
|
@ -11,7 +11,7 @@ try{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(\Exception){
|
catch(\Exception){
|
||||||
http_response_code(500);
|
http_response_code(Enums\HttpCode::InternalServerError->value);
|
||||||
include(WEB_ROOT . '/404.php');
|
include(WEB_ROOT . '/404.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,5 @@ if($url != ''){
|
||||||
$url = '/' . $url;
|
$url = '/' . $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
http_response_code(302);
|
http_response_code(Enums\HttpCode::Found->value);
|
||||||
header('Location: /manual/' . $currentManual . $url);
|
header('Location: /manual/' . $currentManual . $url);
|
||||||
|
|
|
@ -11,7 +11,7 @@ try{
|
||||||
$_SESSION['subscription-confirmed'] = $subscription->UserId;
|
$_SESSION['subscription-confirmed'] = $subscription->UserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: ' . $subscription->Url);
|
header('Location: ' . $subscription->Url);
|
||||||
}
|
}
|
||||||
catch(Exceptions\NewsletterSubscriptionNotFoundException){
|
catch(Exceptions\NewsletterSubscriptionNotFoundException){
|
||||||
|
|
|
@ -17,7 +17,7 @@ catch(Exceptions\NewsletterSubscriptionNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
http_response_code(404);
|
http_response_code(Enums\HttpCode::NotFound->value);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ try{
|
||||||
|
|
||||||
if($created){
|
if($created){
|
||||||
// HTTP 201 Created
|
// HTTP 201 Created
|
||||||
http_response_code(201);
|
http_response_code(Enums\HttpCode::Created->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exceptions\AppException){
|
catch(Exceptions\AppException){
|
||||||
|
|
|
@ -9,7 +9,7 @@ $subscription = $_SESSION['subscription'] ?? new NewsletterSubscription();
|
||||||
$exception = $_SESSION['exception'] ?? null;
|
$exception = $_SESSION['exception'] ?? null;
|
||||||
|
|
||||||
if($exception){
|
if($exception){
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
session_unset();
|
session_unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ try{
|
||||||
if(HttpInput::Str(POST, 'automationtest')){
|
if(HttpInput::Str(POST, 'automationtest')){
|
||||||
// A bot filled out this form field, which should always be empty. Pretend like we succeeded.
|
// A bot filled out this form field, which should always be empty. Pretend like we succeeded.
|
||||||
if($requestType == Enums\HttpRequestType::Web){
|
if($requestType == Enums\HttpRequestType::Web){
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
$uuid = Uuid::uuid4();
|
$uuid = Uuid::uuid4();
|
||||||
$subscription->User = new User();
|
$subscription->User = new User();
|
||||||
$subscription->User->Uuid = $uuid->toString();
|
$subscription->User->Uuid = $uuid->toString();
|
||||||
|
@ -23,7 +23,7 @@ try{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via Enums\HttpRequestType::Rest api; 201 CREATED with location
|
// Access via Enums\HttpRequestType::Rest api; 201 CREATED with location
|
||||||
http_response_code(201);
|
http_response_code(Enums\HttpCode::Created->value);
|
||||||
header('Location: /newsletter/subscriptions/success');
|
header('Location: /newsletter/subscriptions/success');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ try{
|
||||||
session_unset();
|
session_unset();
|
||||||
|
|
||||||
if($requestType == Enums\HttpRequestType::Web){
|
if($requestType == Enums\HttpRequestType::Web){
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
$_SESSION['is-subscription-created'] = $subscription->UserId;
|
$_SESSION['is-subscription-created'] = $subscription->UserId;
|
||||||
header('Location: /newsletter/subscriptions/success');
|
header('Location: /newsletter/subscriptions/success');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via Enums\HttpRequestType::Rest api; 201 CREATED with location
|
// Access via Enums\HttpRequestType::Rest api; 201 CREATED with location
|
||||||
http_response_code(201);
|
http_response_code(Enums\HttpCode::Created->value);
|
||||||
header('Location: /newsletter/subscriptions/success');
|
header('Location: /newsletter/subscriptions/success');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ catch(Exceptions\NewsletterSubscriptionExistsException){
|
||||||
$subscription->IsConfirmed = $existingSubscription->IsConfirmed;
|
$subscription->IsConfirmed = $existingSubscription->IsConfirmed;
|
||||||
$subscription->Save();
|
$subscription->Save();
|
||||||
|
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
|
|
||||||
if(!$subscription->IsConfirmed){
|
if(!$subscription->IsConfirmed){
|
||||||
// Don't re-send the email after all, to prevent spam
|
// Don't re-send the email after all, to prevent spam
|
||||||
|
@ -77,7 +77,7 @@ catch(Exceptions\NewsletterSubscriptionExistsException){
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via Enums\HttpRequestType::Rest api; 409 CONFLICT
|
// Access via Enums\HttpRequestType::Rest api; 409 CONFLICT
|
||||||
http_response_code(409);
|
http_response_code(Enums\HttpCode::Conflict->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidNewsletterSubscription $ex){
|
catch(Exceptions\InvalidNewsletterSubscription $ex){
|
||||||
|
@ -86,11 +86,11 @@ catch(Exceptions\InvalidNewsletterSubscription $ex){
|
||||||
$_SESSION['exception'] = $ex;
|
$_SESSION['exception'] = $ex;
|
||||||
|
|
||||||
// Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity
|
// Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: /newsletter/subscriptions/new');
|
header('Location: /newsletter/subscriptions/new');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via Enums\HttpRequestType::Rest api; 422 Unprocessable Entity
|
// Access via Enums\HttpRequestType::Rest api; 422 Unprocessable Entity
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ if(isset($_SESSION['is-subscription-created'])){
|
||||||
|
|
||||||
if($created){
|
if($created){
|
||||||
// HTTP 201 Created
|
// HTTP 201 Created
|
||||||
http_response_code(201);
|
http_response_code(Enums\HttpCode::Created->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
?><?= Template::Header(['title' => 'Your subscription to the Standard Ebooks newsletter', 'highlight' => 'newsletter', 'description' => 'Your subscription to the Standard Ebooks newsletter.']) ?>
|
?><?= Template::Header(['title' => 'Your subscription to the Standard Ebooks newsletter', 'highlight' => 'newsletter', 'description' => 'Your subscription to the Standard Ebooks newsletter.']) ?>
|
||||||
|
|
|
@ -11,7 +11,7 @@ try{
|
||||||
|
|
||||||
if(isset($_SESSION['is-vote-created']) && $_SESSION['is-vote-created'] == $vote->UserId){
|
if(isset($_SESSION['is-vote-created']) && $_SESSION['is-vote-created'] == $vote->UserId){
|
||||||
$created = true;
|
$created = true;
|
||||||
http_response_code(201);
|
http_response_code(Enums\HttpCode::Created->value);
|
||||||
session_unset();
|
session_unset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
if($exception){
|
if($exception){
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
session_unset();
|
session_unset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@ try{
|
||||||
|
|
||||||
if($requestType == Enums\HttpRequestType::Web){
|
if($requestType == Enums\HttpRequestType::Web){
|
||||||
$_SESSION['is-vote-created'] = $vote->UserId;
|
$_SESSION['is-vote-created'] = $vote->UserId;
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: ' . $vote->Url);
|
header('Location: ' . $vote->Url);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via Enums\HttpRequestType::Rest api; 201 CREATED with location
|
// Access via Enums\HttpRequestType::Rest api; 201 CREATED with location
|
||||||
http_response_code(201);
|
http_response_code(Enums\HttpCode::Created->value);
|
||||||
header('Location: ' . $vote->Url);
|
header('Location: ' . $vote->Url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,11 @@ catch(Exceptions\InvalidPollVoteException $ex){
|
||||||
$_SESSION['exception'] = $ex;
|
$_SESSION['exception'] = $ex;
|
||||||
|
|
||||||
// Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity
|
// Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: /polls/' . (HttpInput::Str(GET, 'pollurlname') ?? '') . '/votes/new');
|
header('Location: /polls/' . (HttpInput::Str(GET, 'pollurlname') ?? '') . '/votes/new');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via Enums\HttpRequestType::Rest api; 422 Unprocessable Entity
|
// Access via Enums\HttpRequestType::Rest api; 422 Unprocessable Entity
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,18 +14,18 @@ $redirect = HttpInput::Str(SESSION, 'redirect') ?? HttpInput::Str(GET, 'redirect
|
||||||
$exception = $_SESSION['exception'] ?? null;
|
$exception = $_SESSION['exception'] ?? null;
|
||||||
$passwordRequired = false;
|
$passwordRequired = false;
|
||||||
|
|
||||||
http_response_code(401);
|
http_response_code(Enums\HttpCode::Unauthorized->value);
|
||||||
|
|
||||||
if($exception){
|
if($exception){
|
||||||
if($exception instanceof Exceptions\PasswordRequiredException){
|
if($exception instanceof Exceptions\PasswordRequiredException){
|
||||||
// This login requires a password to proceed.
|
// This login requires a password to proceed.
|
||||||
// Prompt the user for a password.
|
// Prompt the user for a password.
|
||||||
http_response_code(401);
|
http_response_code(Enums\HttpCode::Unauthorized->value);
|
||||||
$passwordRequired = true;
|
$passwordRequired = true;
|
||||||
$exception = null; // Clear the exception so we don't show an error
|
$exception = null; // Clear the exception so we don't show an error
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
}
|
}
|
||||||
session_unset();
|
session_unset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,12 @@ try{
|
||||||
session_unset();
|
session_unset();
|
||||||
|
|
||||||
if($requestType == Enums\HttpRequestType::Web){
|
if($requestType == Enums\HttpRequestType::Web){
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: ' . $redirect);
|
header('Location: ' . $redirect);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via Enums\HttpRequestType::Rest api; 201 CREATED with location
|
// Access via Enums\HttpRequestType::Rest api; 201 CREATED with location
|
||||||
http_response_code(201);
|
http_response_code(Enums\HttpCode::Created->value);
|
||||||
header('Location: ' . $session->Url);
|
header('Location: ' . $session->Url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,11 @@ catch(Exceptions\InvalidLoginException | Exceptions\PasswordRequiredException $e
|
||||||
$_SESSION['exception'] = $ex;
|
$_SESSION['exception'] = $ex;
|
||||||
|
|
||||||
// Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity
|
// Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: /sessions/new');
|
header('Location: /sessions/new');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Access via Enums\HttpRequestType::Rest api; 422 Unprocessable Entity
|
// Access via Enums\HttpRequestType::Rest api; 422 Unprocessable Entity
|
||||||
http_response_code(422);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ if($colorScheme !== null){
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP 303, See other
|
// HTTP 303, See other
|
||||||
http_response_code(303);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
|
|
||||||
$redirect = $_SERVER['HTTP_REFERER'] ?? '/';
|
$redirect = $_SERVER['HTTP_REFERER'] ?? '/';
|
||||||
header('Location: ' . $redirect);
|
header('Location: ' . $redirect);
|
||||||
|
|
|
@ -131,11 +131,11 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Success, no content"
|
// "Success, no content"
|
||||||
http_response_code(204);
|
http_response_code(Enums\HttpCode::NoContent->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidCredentialsException){
|
catch(Exceptions\InvalidCredentialsException){
|
||||||
// "Forbidden"
|
// "Forbidden"
|
||||||
http_response_code(403);
|
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\WebhookException $ex){
|
catch(Exceptions\WebhookException $ex){
|
||||||
// Uh oh, something went wrong!
|
// Uh oh, something went wrong!
|
||||||
|
@ -147,13 +147,13 @@ catch(Exceptions\WebhookException $ex){
|
||||||
print($ex->getMessage());
|
print($ex->getMessage());
|
||||||
|
|
||||||
// "Client error"
|
// "Client error"
|
||||||
http_response_code(400);
|
http_response_code(Enums\HttpCode::BadRequest->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\NoopException){
|
catch(Exceptions\NoopException){
|
||||||
// We arrive here because a special case required us to take no action for the request, but execution also had to be interrupted.
|
// We arrive here because a special case required us to take no action for the request, but execution also had to be interrupted.
|
||||||
// For example, we received a request for a known repo for which we must ignore requests.
|
// For example, we received a request for a known repo for which we must ignore requests.
|
||||||
|
|
||||||
// "Success, no content"
|
// "Success, no content"
|
||||||
http_response_code(204);
|
http_response_code(Enums\HttpCode::NoContent->value);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -74,12 +74,12 @@ try{
|
||||||
$log->Write('Event processed.');
|
$log->Write('Event processed.');
|
||||||
|
|
||||||
// "Success, no content"
|
// "Success, no content"
|
||||||
http_response_code(204);
|
http_response_code(Enums\HttpCode::NoContent->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidCredentialsException){
|
catch(Exceptions\InvalidCredentialsException){
|
||||||
// "Forbidden"
|
// "Forbidden"
|
||||||
$log->Write('Invalid key: ' . ($_SERVER['HTTP_X_SE_KEY'] ?? ''));
|
$log->Write('Invalid key: ' . ($_SERVER['HTTP_X_SE_KEY'] ?? ''));
|
||||||
http_response_code(403);
|
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\WebhookException $ex){
|
catch(Exceptions\WebhookException $ex){
|
||||||
// Uh oh, something went wrong!
|
// Uh oh, something went wrong!
|
||||||
|
@ -91,5 +91,5 @@ catch(Exceptions\WebhookException $ex){
|
||||||
print($ex->getMessage());
|
print($ex->getMessage());
|
||||||
|
|
||||||
// "Client error"
|
// "Client error"
|
||||||
http_response_code(400);
|
http_response_code(Enums\HttpCode::BadRequest->value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,12 +51,12 @@ try{
|
||||||
$log->Write('Event processed.');
|
$log->Write('Event processed.');
|
||||||
|
|
||||||
// "Success, no content"
|
// "Success, no content"
|
||||||
http_response_code(204);
|
http_response_code(Enums\HttpCode::NoContent->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\InvalidCredentialsException){
|
catch(Exceptions\InvalidCredentialsException){
|
||||||
// "Forbidden"
|
// "Forbidden"
|
||||||
$log->Write('Couldn\'t validate POST data.');
|
$log->Write('Couldn\'t validate POST data.');
|
||||||
http_response_code(403);
|
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||||
}
|
}
|
||||||
catch(Exceptions\WebhookException $ex){
|
catch(Exceptions\WebhookException $ex){
|
||||||
// Uh oh, something went wrong!
|
// Uh oh, something went wrong!
|
||||||
|
@ -68,5 +68,5 @@ catch(Exceptions\WebhookException $ex){
|
||||||
print($ex->getMessage());
|
print($ex->getMessage());
|
||||||
|
|
||||||
// "Client error"
|
// "Client error"
|
||||||
http_response_code(400);
|
http_response_code(Enums\HttpCode::BadRequest->value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue