Returns 401 / Unauthorized.

@param string $message

@return \Illuminate\Http\JsonResponse
170686
public function respondUnauthorized($message = null): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_UNAUTHORIZED)
            ->respondWithError(ApiResponse::CODE_NOT_AUTHORIZED, $message);
    }
201461
public function validInternalServerErrorJsonResponse($exception, $message = 'Error')
    {
        return response()->json(
            [
                'exception' => class_basename($exception),
                'file' => basename($exception->getFile()),
                'line' => $exception->getLine(),
                'message' => $exception->getMessage(),
                'trace' => $exception->getTrace(),
            ], 500, [], JSON_PRETTY_PRINT
        );
    }
241663
protected function isValidMessage($message): Message
    {
        if ($message instanceof Message) {
            return $message;
        }

        if (\is_string($message) || $message instanceof Attachment) {
            return Message::create($message);
        }

        throw new MessengerException(sprintf(
            'message must be a string or an instance of %s or %s.',
            Message::class,
            Attachment::class
        ));
    }
965809
public function send($message)
    {
        try {
            $code = 200;
            $this->sendEvent($this->targetServiceName, $message);
            $message = 'Event has been sent';
        } catch (\Exception $exception) {
            $message = $exception->getMessage();
            $code = $exception->getCode();
        }

        return new Response(
            json_encode(['message' => $message]),
            (!empty($code)) ? $code : 500
        );
    }
448684
public static function new($message): self
    {
        if (is_object($message)) {
            return new static($message);
        }

        if (is_array($message)) {
            return new static(json_decode(json_encode($message)));
        }

        if (is_string($message)) {
            return new static(json_decode($message));
        }

        throw new InvalidArgumentException('The given message was neither an object, array nor JSON.');
    }
252609
public function parseException($e, $message = '')
    {
        $response = [
            'code' => $e->getCode(),
            'response' => $message . ' ' . $e->getMessage(),
            'error' => (bool)true
        ];
        return $response;
    }
668669
private function uriSafeEncode($message)
    {
        $encoded = base64_encode($message);
        $uriSafe = str_replace(['+', '/'], ['-', '_'], $encoded);

        return rtrim($uriSafe, '=');
    }
1043772
public function fromMessage($message)
    {
        static $parser;
        if (!$parser) {
            $parser = new MessageParser();
        }

        // Parse a response
        if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
            $data = $parser->parseResponse($message);
            return $this->createResponse(
                $data['code'],
                $data['headers'],
                $data['body'] === '' ? null : $data['body'],
                $data
            );
        }

        // Parse a request
        if (!($data = ($parser->parseRequest($message)))) {
            throw new \InvalidArgumentException('Unable to parse request');
        }

        return $this->createRequest(
            $data['method'],
            Url::buildUrl($data['request_url']),
            [
                'headers' => $data['headers'],
                'body' => $data['body'] === '' ? null : $data['body'],
                'config' => [
                    'protocol_version' => $data['protocol_version']
                ]
            ]
        );
    }
460372
function UnauthorizedError(message) {
  Error.call(this);
  Error.captureStackTrace(this, this.constructor);

  this.status = 401;
  this.message = 'Unauthorized: ' + message;
  this.name = this.constructor.name;
}
312498
public function decrypt($message)
    {
        $data = \base64_decode($message, true);

        if ($data === false)
        {
            throw new Exceptions\Invalid('Invalid `message` on decrypt');
        }

        $nonceSize  = \openssl_cipher_iv_length($this->method);
        $nonce      = \mb_substr($data, 0, $nonceSize, '8bit');
        $cipherText = \mb_substr($data, $nonceSize, null, '8bit');

        $plaintext = \openssl_decrypt(
            $cipherText,
            $this->method,
            $this->password,
            OPENSSL_RAW_DATA,
            $nonce
        );

        return $plaintext;
    }
348684
protected function buildResponse($message)
    {
        if (empty($message) || $message === self::SUCCESS_EMPTY_RESPONSE) {
            return self::SUCCESS_EMPTY_RESPONSE;
        }

        return self::FAILED_EMPTY_RESPONSE;
    }
613966
public function encrypt($message)
    {

        $nonceSize = \openssl_cipher_iv_length($this->method);
        $nonce     = \openssl_random_pseudo_bytes($nonceSize, $cryptStrong);

        if (false === $cryptStrong || false === $nonce)
        {
            throw new Exceptions\Runtime('IV generation failed');
        }

        $cipherText = \openssl_encrypt(
            $message,
            $this->method,
            $this->password,
            OPENSSL_RAW_DATA,
            $nonce
        );

        return \base64_encode($nonce . $cipherText);
    }
1113525
protected function getResponse(IncomingMessage $message)
    {
        $response = $this->http->post($this->apiUrl, [], [
            'query' => [$message->getText()],
            'sessionId' => md5($message->getConversationIdentifier()),
            'lang' => $this->lang,
        ], [
            'Authorization: Bearer '.$this->token,
            'Content-Type: application/json; charset=utf-8',
        ], true);

        $this->response = json_decode($response->getContent());

        return $this->response;
    }
63144
public function getFrom(Message $message = null) 
    {
        $from = $message === null ? null : $message->getFrom();
        if (!$from) {
            $from = $this->getOption(self::CONFIG_DEFAULT_SENDER);
        }
        return $from;
    }
720515
protected function formatMessage($message)
    {
        if (is_array($message)) {
            $message = var_export($message, true);
        } elseif (is_object($message)) {
            $message = get_object_vars($message);
        }

        return $message;
    }
206831
public static function decodeMessage(string $message): Message
    {
        $offset = 0;
        $header = self::decodeHeader($message, $offset);
        $messageObject = new Message($header);
        $messageObject->setQuestions(self::decodeResourceRecords($message, $header->getQuestionCount(), $offset, true));
        $messageObject->setAnswers(self::decodeResourceRecords($message, $header->getAnswerCount(), $offset));
        $messageObject->setAuthoritatives(self::decodeResourceRecords($message, $header->getNameServerCount(), $offset));
        $messageObject->setAdditionals(self::decodeResourceRecords($message, $header->getAdditionalRecordsCount(), $offset));

        return $messageObject;
    }
633074
protected function badRequest(string $message = 'Bad request.'): Response
    {
        return $this->getResponse()
            ->setContent($message)
            ->setStatusCode(Response::HTTP_BAD_REQUEST);
    }