fix(files_sharing): Cleanup error messages

Signed-off-by: provokateurin <kate@provokateurin.de>
This commit is contained in:
provokateurin 2024-10-22 08:20:04 +02:00
parent e6c11e1be0
commit aacb3ddc1e
No known key found for this signature in database
3 changed files with 11 additions and 11 deletions

View file

@ -646,7 +646,7 @@ class ShareAPIController extends OCSController {
$expireDateTime = $this->parseDate($expireDate);
$share->setExpirationDate($expireDateTime);
} catch (\Exception $e) {
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
throw new OCSNotFoundException($e->getMessage(), $e);
}
} else {
// Client sent empty string for expire date.
@ -812,12 +812,11 @@ class ShareAPIController extends OCSController {
try {
$share = $this->shareManager->createShare($share);
} catch (GenericShareException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), $code);
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSForbiddenException($e->getMessage(), $e);
throw new OCSForbiddenException('Failed to create share.', $e);
}
$output = $this->formatShare($share);
@ -1349,11 +1348,11 @@ class ShareAPIController extends OCSController {
$share->setExpirationDate(null);
} elseif ($expireDate !== null) {
try {
$expireDate = $this->parseDate($expireDate);
$expireDateTime = $this->parseDate($expireDate);
$share->setExpirationDate($expireDateTime);
} catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage(), $e);
}
$share->setExpirationDate($expireDate);
}
try {
@ -1362,7 +1361,8 @@ class ShareAPIController extends OCSController {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), (int)$code);
} catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage(), $e);
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSBadRequestException('Failed to update share.', $e);
}
return new DataResponse($this->formatShare($share));
@ -1449,7 +1449,8 @@ class ShareAPIController extends OCSController {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), (int)$code);
} catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage(), $e);
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSBadRequestException('Failed to accept share.', $e);
}
return new DataResponse();
@ -2141,9 +2142,8 @@ class ShareAPIController extends OCSController {
$provider->sendMailNotification($share);
return new DataResponse();
} catch (OCSBadRequestException $e) {
throw $e;
} catch (Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new OCSException($this->l->t('Error while sending mail notification'));
}

View file

@ -1299,7 +1299,7 @@ class ApiTest extends TestCase {
$this->assertTrue($valid);
} catch (OCSNotFoundException $e) {
$this->assertFalse($valid);
$this->assertEquals('Invalid date, date format must be YYYY-MM-DD', $e->getMessage());
$this->assertEquals('Invalid date. Format must be YYYY-MM-DD', $e->getMessage());
$ocs->cleanup();
return;
}

View file

@ -2217,7 +2217,7 @@ class ShareAPIControllerTest extends TestCase {
public function testCreateShareInvalidExpireDate(): void {
$this->expectException(OCSNotFoundException::class);
$this->expectExceptionMessage('Invalid date, date format must be YYYY-MM-DD');
$this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD');
$ocs = $this->mockFormatShare();