Exceptions

The most important function of Streply is to catch errors and exceptions from the application. The integration is very simple, just calling one method in the catch instruction.

Forwarding an exception to Streply is very easy, just call the Streply\Exception method in the catch condition and pass the entire exception object to it.

try {
    if(true) {
        throw new \Exceptions\SomeException('Exception message here');
    }
} catch(\Throwable $exception) {
    Streply\Exception($exception);
}

The method consists of the following parameters:

function Exception(
    \Throwable $exception,
    array $params = [],
    string $level = Streply\Enum\Level::NORMAL
): void
  • \Throwable $exception - Intercepted exception
  • array $params - Array of optional parameters
  • string $level - Error level

As a second parameter, we can add additional information that is important to us and not present in the error object (e.g. user ID).

To send an activity, e.g. a correct login to the system, simply call:

try {
    if(true) {
        throw new \Exceptions\SomeException('Exception message here');
    }
} catch(\Throwable $exception) {
    Streply\Exception(
        $exception,
        [
            'userId' => 5,
            'userName' => 'Jon Doe'
        ]
    );
}

The third parameter is the error level, which means how important it is. By default, each error takes the value Streply\Enum\Level::NORMAL.

Available error levels

  • Streply\Enum\Level::LOW
  • Streply\Enum\Level::NORMAL
  • Streply\Enum\Level::HIGH
  • Streply\Enum\Level::CRITICAL

Based on the error level, we can set notifications and search criteria (e.g. show errors with a critical level).