Преглед на файлове

Catch more error codes thrown by federated shares

Most of the time it doesn't make sense to forward Guzzle's
RequestException, so we convert it to StorageNotAvailable instead.

This prevents unpredictable error codes to block access to unrelated
folders needlessly.
tags/v8.2beta1
Vincent Petry преди 9 години
родител
ревизия
5d3aa36355
променени са 1 файла, в които са добавени 7 реда и са изтрити 13 реда
  1. 7
    13
      apps/files_sharing/lib/external/storage.php

+ 7
- 13
apps/files_sharing/lib/external/storage.php Целия файл

throw new StorageInvalidException(); throw new StorageInvalidException();
} else { } else {
// ownCloud instance is gone, likely to be a temporary server configuration error // ownCloud instance is gone, likely to be a temporary server configuration error
throw $e;
throw new StorageNotAvailableException();
} }
} catch (ForbiddenException $e) { } catch (ForbiddenException $e) {
// auth error, remove share for now (provide a dialog in the future) // auth error, remove share for now (provide a dialog in the future)
} catch (\GuzzleHttp\Exception\ConnectException $e) { } catch (\GuzzleHttp\Exception\ConnectException $e) {
throw new StorageNotAvailableException(); throw new StorageNotAvailableException();
} catch (\GuzzleHttp\Exception\RequestException $e) { } catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->getCode() === 503) {
throw new StorageNotAvailableException();
}
throw $e;
throw new StorageNotAvailableException();
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
} }
try { try {
$response = $client->post($url, ['body' => ['password' => $password]]); $response = $client->post($url, ['body' => ['password' => $password]]);
} catch (\GuzzleHttp\Exception\RequestException $e) { } catch (\GuzzleHttp\Exception\RequestException $e) {
switch ($e->getCode()) {
case 401:
case 403:
if ($e->getCode() === 401 || $e->getCode() === 403) {
throw new ForbiddenException(); throw new ForbiddenException();
case 404:
throw new NotFoundException();
case 500:
throw new \Exception();
} }
throw $e;
// throw this to be on the safe side: the share will still be visible
// in the UI in case the failure is intermittent, and the user will
// be able to decide whether to remove it if it's really gone
throw new NotFoundException();
} }


return json_decode($response->getBody(), true); return json_decode($response->getBody(), true);

Loading…
Отказ
Запис