Skip to content

Commit

Permalink
Merge pull request #1 from OpenClassrooms/OC-5468_fix_500_on_command
Browse files Browse the repository at this point in the history
handle 500 errors
  • Loading branch information
romainkuzniak authored Jun 29, 2016
2 parents 0530c2c + 9448809 commit 3b33b03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gateways/Impl/FileGatewayImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace OpenClassrooms\Bundle\OneSkyBundle\Gateways\Impl;

use Guzzle\Http\Exception\ServerErrorResponseException;
use Onesky\Api\Client;
use OpenClassrooms\Bundle\OneSkyBundle\EventListener\TranslationDownloadTranslationEvent;
use OpenClassrooms\Bundle\OneSkyBundle\EventListener\TranslationUploadTranslationEvent;
Expand Down Expand Up @@ -73,6 +74,9 @@ private function checkTranslation($downloadedContent, ExportFile $file)
if (400 === $json['meta']['status']) {
throw new NonExistingTranslationException($file->getTargetFilePath());
}
if (500 === $json['meta']['status']) {
throw new ServerErrorResponseException($file->getTargetFilePath());
}
throw new InvalidContentException($downloadedContent);
}
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/Gateways/Impl/FileGatewayImplTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ public function WithFileNotOnApiException_download_DoNothing()
$this->gateway->downloadTranslations([new ExportFileStub1()]);
}

/**
* @test
* @expectedException \Guzzle\Http\Exception\ServerErrorResponseException
*/
public function ApiServerError_download_ThrowException()
{
ClientMock::$downloadedContent = '{"meta":{"status":500,"message":"Something went wrong. Please try again or contact us at [email protected]"},"data":{}}';
$this->gateway->downloadTranslations([new ExportFileStub1()]);
}

/**
* @test
*/
Expand Down

0 comments on commit 3b33b03

Please sign in to comment.