1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-09-19 15:11:40 +02:00

Catch Exceptions thrown by StatHelper and throw an ApiException

This commit is contained in:
Chaoyi Zha 2017-03-20 17:34:09 -04:00
parent fc056a9364
commit eb8b27a341
2 changed files with 10 additions and 1 deletions

View File

@ -46,7 +46,12 @@ class ApiAnalyticsController extends ApiController {
throw new ApiException('ACCESS_DENIED', 'Unauthorized.', 401, $response_type);
}
$stats = new StatsHelper($link->id, $left_bound, $right_bound);
try {
$stats = new StatsHelper($link->id, $left_bound, $right_bound);
}
catch (\Exception $e) {
throw new ApiException('ANALYTICS_ERROR', $e->getMessage(), 400, $response_type);
}
if ($stats_type == 'day') {
$fetched_stats = $stats->getDayStats();

View File

@ -1,4 +1,6 @@
## API Error Text Codes
To diagnose an unexpected or unhandled error, turn on the `APP_DEBUG` flag by setting
it to `true` in `.env`
`SERVER_ERROR`: A generic, unhandled error has occured.
@ -17,3 +19,5 @@
`AUTH_ERROR`: An error occured while attempting to authenticate the user to the API.
`QUOTA_EXCEEDED`: User's API usage has exceeded alloted quota.
`ANALYTICS_ERROR`: Invalid bounds or unexpected error while fetching analytics data.