Пример #1
0
 /**
  * Create response string for problem during request and set HTTP error code
  *
  * @param \Exception $exception
  * @param \Magento\Framework\HTTP\PhpEnvironment\Response $response OPTIONAL If NULL - will use internal getter
  * @return array
  */
 public function prepareErrorResponse(\Exception $exception, \Magento\Framework\HTTP\PhpEnvironment\Response $response = null)
 {
     $errorMsg = $exception->getMessage();
     if ($exception instanceof \Magento\Framework\Oauth\Exception) {
         $responseCode = self::HTTP_UNAUTHORIZED;
     } elseif ($exception instanceof \Magento\Framework\Oauth\OauthInputException) {
         $responseCode = self::HTTP_BAD_REQUEST;
         if ($errorMsg == \Magento\Framework\Oauth\OauthInputException::DEFAULT_MESSAGE) {
             $errorMsg = $exception->getAggregatedErrorMessage();
         }
     } else {
         $errorMsg = 'internal_error&message=' . ($errorMsg ? $errorMsg : 'empty_message');
         $responseCode = self::HTTP_INTERNAL_ERROR;
     }
     $response->setHttpResponseCode($responseCode);
     return ['oauth_problem' => $errorMsg];
 }
Пример #2
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessageRegExp Invalid HTTP response code
  */
 public function testHttpResponseCodeWithException()
 {
     $this->response->setHttpResponseCode(1);
 }