Skip to content

Commit

Permalink
Add Authentication401Exception for failed HTTP Authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Jan 13, 2015
1 parent 0b80bcf commit 65039e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Elasticsearch/Common/Exceptions/Authentication401Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Elasticsearch\Common\Exceptions;

/**
* Authentication401Exception, thrown on 401 authentication http error
*
* @category Elasticsearch
* @package Elasticsearch\Common\Exceptions
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/
class Authentication401Exception extends \Exception implements ElasticsearchException
{
}
3 changes: 3 additions & 0 deletions src/Elasticsearch/Connections/CurlMultiConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Elasticsearch\Connections;

use Elasticsearch\Common\Exceptions\AlreadyExpiredException;
use Elasticsearch\Common\Exceptions\Authentication401Exception;
use Elasticsearch\Common\Exceptions\BadRequest400Exception;
use Elasticsearch\Common\Exceptions\Conflict409Exception;
use Elasticsearch\Common\Exceptions\Forbidden403Exception;
Expand Down Expand Up @@ -278,6 +279,8 @@ private function process4xxError($method, $uri, $request, $response)

if ($statusCode === 400 && strpos($responseBody, "AlreadyExpiredException") !== false) {
throw new AlreadyExpiredException($responseBody, $statusCode);
} elseif ($statusCode === 401) {
throw new Authentication401Exception($responseBody, $statusCode);
} elseif ($statusCode === 403) {
throw new Forbidden403Exception($responseBody, $statusCode);
} elseif ($statusCode === 404) {
Expand Down
3 changes: 3 additions & 0 deletions src/Elasticsearch/Connections/GuzzleConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


use Elasticsearch\Common\Exceptions\AlreadyExpiredException;
use Elasticsearch\Common\Exceptions\Authentication401Exception;
use Elasticsearch\Common\Exceptions\BadRequest400Exception;
use Elasticsearch\Common\Exceptions\Conflict409Exception;
use Elasticsearch\Common\Exceptions\Forbidden403Exception;
Expand Down Expand Up @@ -253,6 +254,8 @@ private function process4xxError(Request $request, ClientErrorResponseException

if ($statusCode === 400 && strpos($responseBody, "AlreadyExpiredException") !== false) {
throw new AlreadyExpiredException($responseBody, $statusCode, $exception);
} elseif ($statusCode === 401) {
throw new Authentication401Exception($responseBody, $statusCode, $exception);
} elseif ($statusCode === 403) {
throw new Forbidden403Exception($responseBody, $statusCode, $exception);
} elseif ($statusCode === 404) {
Expand Down

0 comments on commit 65039e8

Please sign in to comment.