forked from Cavemanon/cavepaintings
more error handling
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Class SCoreException
|
||||
*
|
||||
* A base exception to be caught by the upper levels.
|
||||
*/
|
||||
class SCoreException extends RuntimeException
|
||||
@@ -34,8 +32,6 @@ class InstallerException extends RuntimeException
|
||||
}
|
||||
|
||||
/**
|
||||
* Class PermissionDeniedException
|
||||
*
|
||||
* A fairly common, generic exception.
|
||||
*/
|
||||
class PermissionDeniedException extends SCoreException
|
||||
@@ -43,16 +39,19 @@ class PermissionDeniedException extends SCoreException
|
||||
}
|
||||
|
||||
/**
|
||||
* Class ImageDoesNotExist
|
||||
*
|
||||
* This exception is used when an Image cannot be found by ID.
|
||||
*
|
||||
* Example: Image::by_id(-1) returns null
|
||||
*/
|
||||
class ImageDoesNotExist extends SCoreException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This exception is used when a User cannot be found by some criteria.
|
||||
*/
|
||||
class UserDoesNotExist extends SCoreException
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* For validate_input()
|
||||
*/
|
||||
|
@@ -119,7 +119,7 @@ class Image
|
||||
|
||||
if (SPEED_HAX) {
|
||||
if (!$user->can(Permissions::BIG_SEARCH) and count($tags) > 3) {
|
||||
throw new SCoreException("Anonymous users may only search for up to 3 tags at a time");
|
||||
throw new PermissionDeniedException("Anonymous users may only search for up to 3 tags at a time");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -97,7 +97,7 @@ class User
|
||||
{
|
||||
$u = User::by_name($name);
|
||||
if (is_null($u)) {
|
||||
throw new ScoreException("Can't find any user named $name");
|
||||
throw new UserDoesNotExist("Can't find any user named $name");
|
||||
} else {
|
||||
return $u->id;
|
||||
}
|
||||
|
@@ -616,7 +616,7 @@ function _fatal_error(Exception $e): void
|
||||
print("Version: $version (on $phpver)\n");
|
||||
} else {
|
||||
$q = $query ? "" : "<p><b>Query:</b> " . html_escape($query);
|
||||
error_log("Shimmie Error: $message // $query // {$e->getTraceAsString()}");
|
||||
error_log("Shimmie Error: $message (Query: $query)\n{$e->getTraceAsString()}");
|
||||
header("HTTP/1.0 500 Internal Error");
|
||||
echo '
|
||||
<!doctype html>
|
||||
|
Reference in New Issue
Block a user