Controller.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if (config('app.env') == 'production') {
  36. Response::fail(T('An unknown error was encountered.'), ResponseCodeEnum::SYSTEM_ERROR);
  37. } else {
  38. Response::fail($exception->getMessage(), ResponseCodeEnum::SYSTEM_ERROR);
  39. }
  40. }
  41. public function errorFail()
  42. {
  43. return Response::fail(T('The operation failure.'), ResponseCodeEnum::SERVICE_UPDATE_DATA_ERROR);
  44. }
  45. public function error($msg)
  46. {
  47. return Response::fail($msg, ResponseCodeEnum::SERVICE_UPDATE_DATA_ERROR);
  48. }
  49. }