Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_texteditor.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-10-09 18:29:06 +0300
committerBjoern Schiessle <schiessle@owncloud.com>2015-10-09 18:39:12 +0300
commit6b630d25f3828915f41e39b942852fe8f2406da2 (patch)
tree62eb926a9ee41d92b18cdb2f4e64c7e2e3e71849
parent371192a947302884a2c5d8f8d4d1f75bf1d4edd9 (diff)
if the exception contain a hint what went wrong we display it to the user
-rw-r--r--controller/filehandlingcontroller.php7
-rw-r--r--tests/controller/filehandlingcontrollertest.php22
2 files changed, 26 insertions, 3 deletions
diff --git a/controller/filehandlingcontroller.php b/controller/filehandlingcontroller.php
index 3036431..646e386 100644
--- a/controller/filehandlingcontroller.php
+++ b/controller/filehandlingcontroller.php
@@ -109,7 +109,12 @@ class FileHandlingController extends Controller{
}
} catch (\Exception $e) {
- return new DataResponse(['message' => 'An internal server error occurred.'], Http::STATUS_BAD_REQUEST);
+ if(method_exists($e, 'getHint')) {
+ $message = (string)$e->getHint();
+ } else {
+ $message = (string)$this->l->t('An internal server error occurred.');
+ }
+ return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
}
}
diff --git a/tests/controller/filehandlingcontrollertest.php b/tests/controller/filehandlingcontrollertest.php
index 3e78c1d..70d7fee 100644
--- a/tests/controller/filehandlingcontrollertest.php
+++ b/tests/controller/filehandlingcontrollertest.php
@@ -116,14 +116,14 @@ class FileHandlingControllerTest extends TestCase {
);
}
- public function testLoadException() {
+ public function testLoadExceptionWithNoHint() {
$exceptionHint = 'test exception';
$this->viewMock->expects($this->any())
->method('file_get_contents')
->willReturnCallback(function() use ($exceptionHint) {
- throw new HintException('error message', $exceptionHint);
+ throw new \Exception();
});
$result = $this->controller->load('/', 'test.txt');
@@ -134,6 +134,24 @@ class FileHandlingControllerTest extends TestCase {
$this->assertSame('An internal server error occurred.', $data['message']);
}
+ public function testLoadExceptionWithHint() {
+
+ $exceptionHint = 'test exception';
+
+ $this->viewMock->expects($this->any())
+ ->method('file_get_contents')
+ ->willReturnCallback(function() use ($exceptionHint) {
+ throw new HintException('error message', $exceptionHint);
+ });
+
+ $result = $this->controller->load('/', 'test.txt');
+ $data = $result->getData();
+
+ $this->assertSame(400, $result->getStatus());
+ $this->assertArrayHasKey('message', $data);
+ $this->assertSame($exceptionHint, $data['message']);
+ }
+
/**
* @dataProvider dataTestSave
*