Skip to content

Error Handler ​

Snappy has error handler that centralizes error management and streamlines debugging. It supports flexible output formats — JSON, XML, and HTML — making it ideal for both APIs and web applications.

Settings related to error handling are: errorformat, showerror, logerror and is explained in this page

Error in JSON format

error in JSON format

Error in HTML format

error in HTML format

Error in XML format

error in XML format

Error catching ​

💡 Usage

catch error

php
throw new \Core\Error\ErrorWrapper(Throwable | string $input, int $code = 0): void;

input

  String message or Throwable object

code (optional)

  HTTP response status code

Examples:

php
// with try-catch
try{
  // your logic here
}catch(\Throwable $e){
    throw new \Core\Error\ErrorWrapper($e);
}

// without try-catch
undefinedFunction(); // call an undefined function or anything that cause error
throw new \Core\Error\ErrorWrapper("Error undefined function", 404);

â„šī¸ NOTE

If the error code doesn't represent HTTP response status codes then Error Handler will produce error 500