Skip to content

Commit

Permalink
Merge pull request #27 from keboola/COM-163-ondra-throw-user-exception
Browse files Browse the repository at this point in the history
throw invalidSheet as UserException
  • Loading branch information
ondrajodas authored Mar 11, 2020
2 parents 9f07f6f + 42567bf commit a7fface
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Keboola/GoogleDriveExtractor/Extractor/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ public function run(array $sheets): array
try {
$this->logger->info('Extracting sheet ' . $sheet['sheetTitle']);
$this->export($spreadsheet, $sheet);
} catch (UserException $e) {
throw new UserException($e->getMessage(), 0, $e);
} catch (\Throwable $e) {
$exceptionHandler->handleExportException($e, $sheet);
}
} catch (UserException $e) {
throw new UserException($e->getMessage(), 0, $e);
} catch (\Throwable $e) {
$exceptionHandler->handleGetSpreadsheetException($e, $sheet);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Keboola\GoogleDriveExtractor\Tests;

use Keboola\GoogleDriveExtractor\Application;
use Keboola\GoogleDriveExtractor\Exception\UserException;
use Symfony\Component\Yaml\Yaml;

class ApplicationTest extends BaseTest
Expand Down Expand Up @@ -44,4 +45,15 @@ public function testAppRun(): void

$this->assertEquals($outputTableId, $manifest['destination']);
}

public function testInvalidSpreadsheetId(): void
{
$this->testFile['sheets'][0]['properties']['sheetId'] = 18293729;
$this->config = $this->makeConfig($this->testFile);
$this->application = new Application($this->config);

$this->expectException(UserException::class);
$this->expectExceptionMessage('Sheet id "18293729" not found');
$this->application->run();
}
}

0 comments on commit a7fface

Please sign in to comment.