All packages
Metrics for Laravel
Exceptions
All exceptions extend the abstract RoundlyConsulting\Metrics\Exceptions\MetricsException (itself an Exception), so one catch covers the whole family:
| Exception | Thrown when |
|---|---|
IncompleteMetricException | An inline builder resolves before an aggregate (count, sum, average, max, min) was called. |
InvalidConfigurationException | A metrics.* config value is present but unusable — e.g. a METRICS_CACHE_TTL that isn’t a whole number of seconds between 1 and 31536000, a METRICS_CACHE_ENABLED that isn’t a boolean spelling, an unknown default_range or default_unit, a non-integer precision, a timezone, cache.store, cache.prefix or partition.other_label that isn’t a string, or a trend_drivers entry that isn’t a QueryExpression class. |
InvalidRangeException | A range string can’t be resolved to a Period, or ALL is used where a bounded window is needed (e.g. compareTo(Period::All)). |
InvalidUnitException | A trend query expression receives a unit it doesn’t support. |
MissingTrendQueryExpressionException | A trend runs on a database driver with no registered QueryExpression. |
UnexpectedResultException | A typed metric’s calculate() returned another result type than its base promises (e.g. a Value returning a TrendResult). |
UnknownMetricException | Metrics::get(), Metrics::forget() or a dashboard names an unregistered key. |
use RoundlyConsulting\Metrics\Exceptions\MetricsException;
use RoundlyConsulting\Metrics\Exceptions\UnknownMetricException;
use RoundlyConsulting\Metrics\Facades\Metrics;
try {
return Metrics::get($key)->toArray();
} catch (UnknownMetricException $e) {
abort(404, $e->getMessage());
} catch (MetricsException $e) {
report($e);
abort(500);
}Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.