Improve error handling (#3344)

* Fixes for travis

* Minor Fixes

* Improve Error Handling
This commit is contained in:
David Bomba 2020-02-18 06:07:31 +11:00 committed by GitHub
parent be4cacf198
commit 69cc88e33f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 3 deletions

View File

@ -72,7 +72,7 @@ before_script:
# sh -e /etc/init.d/xvfb start # sh -e /etc/init.d/xvfb start
# sleep 3 # sleep 3
# ./vendor/laravel/dusk/bin/chromedriver-linux & # ./vendor/laravel/dusk/bin/chromedriver-linux &
- php artisan dusk:chrome-driver 72 - php artisan dusk:chrome-driver 80
- php artisan serve & - php artisan serve &
script: script:

View File

@ -71,7 +71,7 @@ class Handler extends ExceptionHandler
public function render($request, Exception $exception) public function render($request, Exception $exception)
{ {
if ($exception instanceof ModelNotFoundException && $request->expectsJson()) { if ($exception instanceof ModelNotFoundException && $request->expectsJson()) {
return response()->json(['message'=>'Record not found'], 400); return response()->json(['message'=>$exception->getMessage()], 400);
} elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) { } elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) {
return response()->json(['message'=>'Too many requests'], 429); return response()->json(['message'=>'Too many requests'], 429);
} elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) { } elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) {

View File

@ -13,6 +13,7 @@ namespace App\Models;
use App\DataMapper\ClientSettings; use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings; use App\DataMapper\CompanySettings;
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
use App\Filters\QueryFilters; use App\Filters\QueryFilters;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\UserSessionAttributes; use App\Utils\Traits\UserSessionAttributes;
@ -153,6 +154,9 @@ class BaseModel extends Model
*/ */
public function resolveRouteBinding($value) public function resolveRouteBinding($value)
{ {
if(is_numeric($value))
throw new ModelNotFoundException("Record with value {$value} not found");
return $this return $this
->withTrashed() ->withTrashed()
->where('id', $this->decodePrimaryKey($value))->firstOrFail(); ->where('id', $this->decodePrimaryKey($value))->firstOrFail();

View File

@ -14,7 +14,7 @@ use App\Models\Payment;
use App\Services\AbstractService; use App\Services\AbstractService;
use App\Services\Customer\CustomerService; use App\Services\Customer\CustomerService;
use App\Services\Payment\PaymentService; use App\Services\Payment\PaymentService;
use App\Traits\GeneratesCounter; use App\Utils\Traits\GeneratesCounter;
class ApplyNumber extends AbstractService class ApplyNumber extends AbstractService
{ {