don't log user errors into the server error log
This commit is contained in:
		
							parent
							
								
									3cb0a6a2c0
								
							
						
					
					
						commit
						68a128c0ea
					
				@ -7,6 +7,7 @@ class SCoreException extends RuntimeException
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public ?string $query;
 | 
					    public ?string $query;
 | 
				
			||||||
    public string $error;
 | 
					    public string $error;
 | 
				
			||||||
 | 
					    public int $http_code = 500;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct(string $msg, ?string $query=null)
 | 
					    public function __construct(string $msg, ?string $query=null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -31,44 +32,58 @@ class InstallerException extends RuntimeException
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UserErrorException extends SCoreException
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public int $http_code = 400;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ServerErrorException extends SCoreException
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public int $http_code = 500;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * A fairly common, generic exception.
 | 
					 * A fairly common, generic exception.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class PermissionDeniedException extends SCoreException
 | 
					class PermissionDeniedException extends UserErrorException
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public int $http_code = 403;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * This exception is used when an Image cannot be found by ID.
 | 
					 * This exception is used when an Image cannot be found by ID.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class ImageDoesNotExist extends SCoreException
 | 
					class ImageDoesNotExist extends UserErrorException
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public int $http_code = 404;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * This exception is used when a User cannot be found by some criteria.
 | 
					 * This exception is used when a User cannot be found by some criteria.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class UserDoesNotExist extends SCoreException
 | 
					class UserDoesNotExist extends UserErrorException
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public int $http_code = 404;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * For validate_input()
 | 
					 * For validate_input()
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class InvalidInput extends SCoreException
 | 
					class InvalidInput extends UserErrorException
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public int $http_code = 402;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * This is used by the image resizing code when there is not enough memory to perform a resize.
 | 
					 * This is used by the image resizing code when there is not enough memory to perform a resize.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class InsufficientMemoryException extends SCoreException
 | 
					class InsufficientMemoryException extends ServerErrorException
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * This is used by the image resizing code when there is an error while resizing
 | 
					 * This is used by the image resizing code when there is an error while resizing
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class ImageResizeException extends SCoreException
 | 
					class ImageResizeException extends ServerErrorException
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -592,6 +592,7 @@ function _fatal_error(Exception $e): void
 | 
				
			|||||||
    $message = $e->getMessage();
 | 
					    $message = $e->getMessage();
 | 
				
			||||||
    $phpver = phpversion();
 | 
					    $phpver = phpversion();
 | 
				
			||||||
    $query = is_subclass_of($e, "SCoreException") ? $e->query : null;
 | 
					    $query = is_subclass_of($e, "SCoreException") ? $e->query : null;
 | 
				
			||||||
 | 
					    $code = is_subclass_of($e, "SCoreException") ? $e->http_code : 500;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //$hash = exec("git rev-parse HEAD");
 | 
					    //$hash = exec("git rev-parse HEAD");
 | 
				
			||||||
    //$h_hash = $hash ? "<p><b>Hash:</b> $hash" : "";
 | 
					    //$h_hash = $hash ? "<p><b>Hash:</b> $hash" : "";
 | 
				
			||||||
@ -616,8 +617,10 @@ function _fatal_error(Exception $e): void
 | 
				
			|||||||
        print("Version: $version (on $phpver)\n");
 | 
					        print("Version: $version (on $phpver)\n");
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        $q = $query ? "" : "<p><b>Query:</b> " . html_escape($query);
 | 
					        $q = $query ? "" : "<p><b>Query:</b> " . html_escape($query);
 | 
				
			||||||
 | 
					        if ($code >= 500) {
 | 
				
			||||||
            error_log("Shimmie Error: $message (Query: $query)\n{$e->getTraceAsString()}");
 | 
					            error_log("Shimmie Error: $message (Query: $query)\n{$e->getTraceAsString()}");
 | 
				
			||||||
        header("HTTP/1.0 500 Internal Error");
 | 
					        }
 | 
				
			||||||
 | 
					        header("HTTP/1.0 $code Error");
 | 
				
			||||||
        echo '
 | 
					        echo '
 | 
				
			||||||
<!doctype html>
 | 
					<!doctype html>
 | 
				
			||||||
<html lang="en">
 | 
					<html lang="en">
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user