+ 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\QueryException;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
@ -18,6 +19,7 @@ use Throwable;
|
|||
class Handler extends ExceptionHandler
|
||||
{
|
||||
use ApiResponser;
|
||||
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*
|
||||
|
@ -57,29 +59,25 @@ class Handler extends ExceptionHandler
|
|||
public function render($request, Throwable $exception)
|
||||
{
|
||||
// return parent::render($request, $exception);
|
||||
if ($exception instanceof HttpException)
|
||||
{
|
||||
if ($exception instanceof HttpException) {
|
||||
$code = $exception->getStatusCode();
|
||||
$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()));
|
||||
|
||||
return $this->errorResponse(trans('errors.model_not_found',['model'=>$model]),
|
||||
return $this->errorResponse(trans('errors.model_not_found', ['model' => $model]),
|
||||
Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
if($exception instanceof AuthorizationException)
|
||||
{
|
||||
return $this->errorResponse($exception->getMessage(),Response::HTTP_UNAUTHORIZED);
|
||||
if ($exception instanceof AuthorizationException) {
|
||||
return $this->errorResponse($exception->getMessage(), Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if($exception instanceof ValidationException)
|
||||
{
|
||||
if ($exception instanceof ValidationException) {
|
||||
$errors = $exception->validator->errors()->getMessages();
|
||||
$message = '';
|
||||
foreach ($errors as $key => $val) {
|
||||
|
@ -92,33 +90,28 @@ class Handler extends ExceptionHandler
|
|||
}
|
||||
|
||||
|
||||
if($exception instanceof AuthenticationException)
|
||||
{
|
||||
return $this->errorResponse($exception->getMessage(),Response::HTTP_UNAUTHORIZED);
|
||||
if ($exception instanceof AuthenticationException) {
|
||||
return $this->errorResponse($exception->getMessage(), Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if ($exception instanceof QueryException)
|
||||
{
|
||||
return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
if ($exception instanceof QueryException) {
|
||||
return $this->errorResponse($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if ($exception instanceof ServerException)
|
||||
{
|
||||
return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
if ($exception instanceof ServerException) {
|
||||
return $this->errorResponse($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if ($exception instanceof \ErrorException)
|
||||
{
|
||||
return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
if ($exception instanceof \ErrorException) {
|
||||
return $this->errorResponse($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if ( $exception instanceof ClientException)
|
||||
{
|
||||
if ($exception instanceof ClientException) {
|
||||
$message = $exception->getResponse()->getBody()->getContents();
|
||||
$error =json_decode($message);
|
||||
$error = json_decode($message);
|
||||
$code = $exception->getCode();
|
||||
|
||||
if($error){
|
||||
if ($error) {
|
||||
if (isset($error->message)) {
|
||||
$message = json_decode($error->message);
|
||||
if (isset($message->errorMessage))
|
||||
|
@ -126,19 +119,21 @@ class Handler extends ExceptionHandler
|
|||
return $this->errorResponse($error->message, $code);
|
||||
}
|
||||
if (isset($error->error)) {
|
||||
try {
|
||||
$message = json_decode($error->error);
|
||||
if (isset($message->message))
|
||||
return $this->errorResponse($message->message, $code);
|
||||
return $this->errorResponse($error->error, $code);
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
return $this->errorResponse($error, $code);
|
||||
} else
|
||||
return $this->errorResponse($message,$code);
|
||||
return $this->errorResponse(json_encode($error->error), $code);
|
||||
}
|
||||
}
|
||||
return $this->errorResponse($message, $code);
|
||||
}
|
||||
|
||||
if( env('APP_DEBUG', false))
|
||||
{
|
||||
return parent::render($request,$exception);
|
||||
if (env('APP_DEBUG', false)) {
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
return $this->errorResponse(trans('errors.unexpected_error'),
|
||||
|
|
|
@ -59,7 +59,7 @@ trait Helper
|
|||
$body->user_code = $user_code;
|
||||
$body->message = $message;
|
||||
$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();
|
||||
// function (ResponseInterface $res) {
|
||||
// echo $res->getStatusCode() . "\n";
|
||||
|
@ -85,7 +85,7 @@ trait Helper
|
|||
$body->agent_code = $agent_code;
|
||||
$body->message = $message;
|
||||
$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->wait();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue