Skip to content

Commit

Permalink
Rename Utils to ExceptionWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndiritu committed Apr 12, 2021
1 parent 36401c9 commit 897ae61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Core/Utils.php → src/Core/ExceptionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the MIT License. See License in the project root
* for license information.
*
* Utils File
* ExceptionWrapper File
* PHP version 7
*
* @category Library
Expand All @@ -21,14 +21,14 @@
use Microsoft\Graph\Exception\GraphException;

/**
* Class Utils
* Class ExceptionWrapper
*
* @category Library
* @package Microsoft.Graph
* @license https://opensource.org/licenses/MIT MIT License
* @link https://graph.microsoft.io/
*/
class Utils
class ExceptionWrapper
{
/**
* Wrap Guzzle BadResponseException which returns truncated exception messages for 4xx and 5xx responses.
Expand Down
8 changes: 4 additions & 4 deletions src/Http/GraphRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use Microsoft\Graph\Core\GraphConstants;
use Microsoft\Graph\Core\Utils;
use Microsoft\Graph\Core\ExceptionWrapper;
use Microsoft\Graph\Exception\GraphException;

/**
Expand Down Expand Up @@ -314,7 +314,7 @@ public function execute($client = null)
]
);
} catch(BadResponseException $e) {
throw Utils::wrapGuzzleBadResponseException($e);
throw ExceptionWrapper::wrapGuzzleBadResponseException($e);
}

// Check to see if returnType is a stream, if so return it immediately
Expand Down Expand Up @@ -386,7 +386,7 @@ function ($result) {
// On fail, log the error and return null
function ($reason) {
if ($reason instanceof BadResponseException) {
$reason = Utils::wrapGuzzleBadResponseException($reason);
$reason = ExceptionWrapper::wrapGuzzleBadResponseException($reason);
}
trigger_error("Async call failed: " . $reason->getMessage());
return null;
Expand Down Expand Up @@ -432,7 +432,7 @@ public function download($path, $client = null)
} catch(GraphException $e) {
throw new GraphException(GraphConstants::INVALID_FILE);
} catch(BadResponseException $e) {
throw Utils::wrapGuzzleBadResponseException($e);
throw ExceptionWrapper::wrapGuzzleBadResponseException($e);
}

return null;
Expand Down
10 changes: 5 additions & 5 deletions tests/Core/UtilsTest.php → tests/Core/ExceptionWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Microsoft\Graph\Core\Utils;
use Microsoft\Graph\Core\ExceptionWrapper;
use Microsoft\Graph\Exception\GraphException;
use PHPUnit\Framework\TestCase;

class UtilsTest extends TestCase
class ExceptionWrapperTest extends TestCase
{
public function testWrapBadResponseExceptionReturnsGraphException()
{
$responseBody = json_encode(array('body' => 'content'));
$ex = new BadResponseException("Error: API returned 400", new Request("GET", "/endpoint"), new Response(400, [], $responseBody));
$graphException = Utils::wrapGuzzleBadResponseException($ex);
$graphException = ExceptionWrapper::wrapGuzzleBadResponseException($ex);
$this->assertInstanceOf(GraphException::class, $graphException);
}

public function testWrapBadResponseExceptionHasResponseBody()
{
$responseBody = json_encode(array('body' => 'content'));
$ex = new BadResponseException("Error: API returned 400", new Request("GET", "/endpoint"), new Response(400, [], $responseBody));
$graphException = Utils::wrapGuzzleBadResponseException($ex);
$graphException = ExceptionWrapper::wrapGuzzleBadResponseException($ex);
$this->assertStringContainsString($responseBody, $graphException->getMessage());
}

public function testWrapBadResponseExceptionWithInvalidInput()
{
$this->expectException(TypeError::class);
Utils::wrapGuzzleBadResponseException(null);
ExceptionWrapper::wrapGuzzleBadResponseException(null);
}
}

0 comments on commit 897ae61

Please sign in to comment.