+ Fix bug while create new users group
This commit is contained in:
		
							parent
							
								
									71ea15813d
								
							
						
					
					
						commit
						d748a84dde
					
				|  | @ -10,6 +10,7 @@ use Illuminate\Auth\AuthenticationException; | ||||||
| use Illuminate\Database\Eloquent\ModelNotFoundException; | use Illuminate\Database\Eloquent\ModelNotFoundException; | ||||||
| use Illuminate\Database\QueryException; | use Illuminate\Database\QueryException; | ||||||
| use Illuminate\Http\Response; | use Illuminate\Http\Response; | ||||||
|  | use Illuminate\Support\Facades\Log; | ||||||
| use Illuminate\Validation\ValidationException; | use Illuminate\Validation\ValidationException; | ||||||
| use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; | use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; | ||||||
| use Symfony\Component\HttpKernel\Exception\HttpException; | use Symfony\Component\HttpKernel\Exception\HttpException; | ||||||
|  | @ -18,6 +19,7 @@ use Throwable; | ||||||
| class Handler extends ExceptionHandler | class Handler extends ExceptionHandler | ||||||
| { | { | ||||||
|     use ApiResponser; |     use ApiResponser; | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * A list of the exception types that should not be reported. |      * A list of the exception types that should not be reported. | ||||||
|      * |      * | ||||||
|  | @ -35,7 +37,7 @@ class Handler extends ExceptionHandler | ||||||
|      * |      * | ||||||
|      * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |      * This is a great spot to send exceptions to Sentry, Bugsnag, etc. | ||||||
|      * |      * | ||||||
|      * @param  \Throwable  $exception |      * @param \Throwable $exception | ||||||
|      * @return void |      * @return void | ||||||
|      * |      * | ||||||
|      * @throws \Exception |      * @throws \Exception | ||||||
|  | @ -48,8 +50,8 @@ class Handler extends ExceptionHandler | ||||||
|     /** |     /** | ||||||
|      * Render an exception into an HTTP response. |      * Render an exception into an HTTP response. | ||||||
|      * |      * | ||||||
|      * @param  \Illuminate\Http\Request  $request |      * @param \Illuminate\Http\Request $request | ||||||
|      * @param  \Throwable  $exception |      * @param \Throwable $exception | ||||||
|      * @return \Symfony\Component\HttpFoundation\Response |      * @return \Symfony\Component\HttpFoundation\Response | ||||||
|      * |      * | ||||||
|      * @throws \Throwable |      * @throws \Throwable | ||||||
|  | @ -57,29 +59,25 @@ class Handler extends ExceptionHandler | ||||||
|     public function render($request, Throwable $exception) |     public function render($request, Throwable $exception) | ||||||
|     { |     { | ||||||
| //        return parent::render($request, $exception);
 | //        return parent::render($request, $exception);
 | ||||||
|         if ($exception instanceof  HttpException) |         if ($exception instanceof HttpException) { | ||||||
|         { |  | ||||||
|             $code = $exception->getStatusCode(); |             $code = $exception->getStatusCode(); | ||||||
|             $message = Response::$statusTexts[$code]; |             $message = Response::$statusTexts[$code]; | ||||||
| 
 | 
 | ||||||
|             return  $this->errorResponse($message,$code); |             return $this->errorResponse($message, $code); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if($exception instanceof ModelNotFoundException) |         if ($exception instanceof ModelNotFoundException) { | ||||||
|         { |  | ||||||
|             $model = strtolower(class_basename($exception->getModel())); |             $model = strtolower(class_basename($exception->getModel())); | ||||||
| 
 | 
 | ||||||
|             return $this->errorResponse(trans('errors.model_not_found',['model'=>$model]), |             return $this->errorResponse(trans('errors.model_not_found', ['model' => $model]), | ||||||
|                 Response::HTTP_NOT_FOUND); |                 Response::HTTP_NOT_FOUND); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if($exception instanceof AuthorizationException) |         if ($exception instanceof AuthorizationException) { | ||||||
|         { |             return $this->errorResponse($exception->getMessage(), Response::HTTP_UNAUTHORIZED); | ||||||
|             return  $this->errorResponse($exception->getMessage(),Response::HTTP_UNAUTHORIZED); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if($exception instanceof ValidationException) |         if ($exception instanceof ValidationException) { | ||||||
|         { |  | ||||||
|             $errors = $exception->validator->errors()->getMessages(); |             $errors = $exception->validator->errors()->getMessages(); | ||||||
|             $message = ''; |             $message = ''; | ||||||
|             foreach ($errors as $key => $val) { |             foreach ($errors as $key => $val) { | ||||||
|  | @ -92,33 +90,28 @@ class Handler extends ExceptionHandler | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         if($exception instanceof AuthenticationException) |         if ($exception instanceof AuthenticationException) { | ||||||
|         { |             return $this->errorResponse($exception->getMessage(), Response::HTTP_UNAUTHORIZED); | ||||||
|             return  $this->errorResponse($exception->getMessage(),Response::HTTP_UNAUTHORIZED); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if ($exception instanceof QueryException) |         if ($exception instanceof QueryException) { | ||||||
|         { |             return $this->errorResponse($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); | ||||||
|             return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if ($exception instanceof ServerException) |         if ($exception instanceof ServerException) { | ||||||
|         { |             return $this->errorResponse($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); | ||||||
|             return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if ($exception instanceof \ErrorException) |         if ($exception instanceof \ErrorException) { | ||||||
|         { |             return $this->errorResponse($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); | ||||||
|             return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if ( $exception instanceof ClientException) |         if ($exception instanceof ClientException) { | ||||||
|         { |  | ||||||
|             $message = $exception->getResponse()->getBody()->getContents(); |             $message = $exception->getResponse()->getBody()->getContents(); | ||||||
|             $error  =json_decode($message); |             $error = json_decode($message); | ||||||
|             $code = $exception->getCode(); |             $code = $exception->getCode(); | ||||||
| 
 | 
 | ||||||
|             if($error){ |             if ($error) { | ||||||
|                 if (isset($error->message)) { |                 if (isset($error->message)) { | ||||||
|                     $message = json_decode($error->message); |                     $message = json_decode($error->message); | ||||||
|                     if (isset($message->errorMessage)) |                     if (isset($message->errorMessage)) | ||||||
|  | @ -126,19 +119,21 @@ class Handler extends ExceptionHandler | ||||||
|                     return $this->errorResponse($error->message, $code); |                     return $this->errorResponse($error->message, $code); | ||||||
|                 } |                 } | ||||||
|                 if (isset($error->error)) { |                 if (isset($error->error)) { | ||||||
|                     $message = json_decode($error->error); |                     try { | ||||||
|                     if (isset($message->message)) |                         $message = json_decode($error->error); | ||||||
|                         return $this->errorResponse($message->message, $code); |                         if (isset($message->message)) | ||||||
|                     return $this->errorResponse($error->error, $code); |                             return $this->errorResponse($message->message, $code); | ||||||
|  |                     } catch (\Exception $e) { | ||||||
|  |                         Log::error($e->getMessage()); | ||||||
|  |                     } | ||||||
|  |                     return $this->errorResponse(json_encode($error->error), $code); | ||||||
|                 } |                 } | ||||||
|                 return $this->errorResponse($error, $code); |             } | ||||||
|             } else |             return $this->errorResponse($message, $code); | ||||||
|                 return $this->errorResponse($message,$code); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if( env('APP_DEBUG', false)) |         if (env('APP_DEBUG', false)) { | ||||||
|         { |             return parent::render($request, $exception); | ||||||
|             return parent::render($request,$exception); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return $this->errorResponse(trans('errors.unexpected_error'), |         return $this->errorResponse(trans('errors.unexpected_error'), | ||||||
|  |  | ||||||
|  | @ -59,7 +59,7 @@ trait Helper | ||||||
|         $body->user_code = $user_code; |         $body->user_code = $user_code; | ||||||
|         $body->message = $message; |         $body->message = $message; | ||||||
|         $body->data = $data; |         $body->data = $data; | ||||||
|         $body->date = $date; |         $body->date = $date->format('Y-m-d H:i:s'); | ||||||
|         $promise = $client->requestAsync('POST', '/onesignal/pushToUser', ['json' => $body, 'headers' => $headers])->then(); |         $promise = $client->requestAsync('POST', '/onesignal/pushToUser', ['json' => $body, 'headers' => $headers])->then(); | ||||||
| //            function (ResponseInterface $res) {
 | //            function (ResponseInterface $res) {
 | ||||||
| //                echo $res->getStatusCode() . "\n";
 | //                echo $res->getStatusCode() . "\n";
 | ||||||
|  | @ -85,7 +85,7 @@ trait Helper | ||||||
|         $body->agent_code = $agent_code; |         $body->agent_code = $agent_code; | ||||||
|         $body->message = $message; |         $body->message = $message; | ||||||
|         $body->data = $data; |         $body->data = $data; | ||||||
|         $body->date = $date; |         $body->date = $date->format('Y-m-d H:i:s'); | ||||||
|         $promise = $client->requestAsync('POST', '/onesignal/pushToAgent', ['json' => $body, 'headers' => $headers])->then(); |         $promise = $client->requestAsync('POST', '/onesignal/pushToAgent', ['json' => $body, 'headers' => $headers])->then(); | ||||||
|         $promise->wait(); |         $promise->wait(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue