Controller.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Http\Controllers;
  11. use App\Repositories\Enums\ResponseCodeEnum;
  12. use Illuminate\Support\Facades\Log;
  13. use Jiannei\Response\Laravel\Support\Facades\Response;
  14. use Jiannei\Response\Laravel\Support\Traits\ExceptionTrait;
  15. use Laravel\Lumen\Routing\Controller as BaseController;
  16. abstract class Controller extends BaseController
  17. {
  18. use ExceptionTrait;
  19. const PAGE_NUM = 15;
  20. public function exception(\Exception $exception)
  21. {
  22. Log::error($exception);
  23. if (config('app.env') == 'production') {
  24. Response::fail(T('An unknown error was encountered.'), ResponseCodeEnum::SYSTEM_ERROR);
  25. } else {
  26. Response::fail($exception->getMessage(), ResponseCodeEnum::SYSTEM_ERROR);
  27. }
  28. }
  29. public function notFound()
  30. {
  31. Response::fail('The resource could not be found.', ResponseCodeEnum::SERVICE_NOT_FIND_DATA_ERROR);
  32. }
  33. public function errorStore($exception)
  34. {
  35. Log::error($exception);
  36. if (config('app.env') == 'production') {
  37. Response::fail(T('An unknown error was encountered.'), ResponseCodeEnum::SYSTEM_ERROR);
  38. } else {
  39. Response::fail($exception->getMessage(), ResponseCodeEnum::SYSTEM_ERROR);
  40. }
  41. }
  42. public function errorFail()
  43. {
  44. return Response::fail(T('The operation failure.'), ResponseCodeEnum::SERVICE_UPDATE_DATA_ERROR);
  45. }
  46. }