+ Fix bug while create new users group

This commit is contained in:
Djery-Tom 2020-12-01 14:47:33 +01:00
parent 71ea15813d
commit d748a84dde
2 changed files with 37 additions and 42 deletions

View File

@ -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);
}
if($exception instanceof ModelNotFoundException)
{
if ($exception instanceof ModelNotFoundException) {
$model = strtolower(class_basename($exception->getModel()));
return $this->errorResponse(trans('errors.model_not_found', ['model' => $model]),
Response::HTTP_NOT_FOUND);
}
if($exception instanceof AuthorizationException)
{
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,28 +90,23 @@ class Handler extends ExceptionHandler
}
if($exception instanceof AuthenticationException)
{
if ($exception instanceof AuthenticationException) {
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);
}
if ($exception instanceof ServerException)
{
if ($exception instanceof ServerException) {
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);
}
if ( $exception instanceof ClientException)
{
if ($exception instanceof ClientException) {
$message = $exception->getResponse()->getBody()->getContents();
$error = json_decode($message);
$code = $exception->getCode();
@ -126,18 +119,20 @@ 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(json_encode($error->error), $code);
}
}
return $this->errorResponse($error, $code);
} else
return $this->errorResponse($message, $code);
}
if( env('APP_DEBUG', false))
{
if (env('APP_DEBUG', false)) {
return parent::render($request, $exception);
}

View File

@ -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();
}