Move handlers to catch more exceptions

This commit is contained in:
Victor Dubiniuk 2013-12-19 01:14:32 +03:00
parent 988ae02b8e
commit d283572fce

View File

@ -18,31 +18,31 @@ class SessionController extends Controller{
$uid = self::preDispatchGuest(); $uid = self::preDispatchGuest();
$uid = substr(@$_POST['name'], 0, 16) .' '. $uid; $uid = substr(@$_POST['name'], 0, 16) .' '. $uid;
$token = @$args['token']; $token = @$args['token'];
$file = File::getByShareToken($token); try {
self::join($uid, $file); $file = File::getByShareToken($token);
self::join($uid, $file);
} catch (\Exception $e){
Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
\OCP\JSON::error();
exit();
}
} }
public static function joinAsUser($args){ public static function joinAsUser($args){
$uid = self::preDispatch(); $uid = self::preDispatch();
$fileId = intval(@$args['file_id']); $fileId = intval(@$args['file_id']);
$file = new File($fileId);
if ($file->getPermissions() & \OCP\PERMISSION_UPDATE) { try {
self::join($uid, $file); $file = new File($fileId);
} else {
\OCP\JSON::success(array(
'permissions' => $file->getPermissions(),
'id' => $fileId
));
}
exit(); if ($file->getPermissions() & \OCP\PERMISSION_UPDATE) {
} self::join($uid, $file);
} else {
protected static function join($uid, $file){ \OCP\JSON::success(array(
try{ 'permissions' => $file->getPermissions(),
$session = Db_Session::start($uid, $file); 'id' => $fileId
\OCP\JSON::success($session); ));
}
exit(); exit();
} catch (\Exception $e){ } catch (\Exception $e){
Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage()); Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
@ -50,6 +50,12 @@ class SessionController extends Controller{
exit(); exit();
} }
} }
protected static function join($uid, $file){
$session = Db_Session::start($uid, $file);
\OCP\JSON::success($session);
exit();
}
/** /**
* Store the document content to its origin * Store the document content to its origin