Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling for file permission issues #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/oauth/persistence/ZohoOAuthPersistenceByFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ public function saveOAuthData($zohoOAuthTokens)
try {
self::deleteOAuthTokens($zohoOAuthTokens->getUserEmailId());
$content = file_get_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt" );

if ($content === false) {
throw new ZohoOAuthException("Can not read tokens file, please check permissions: " . self::getTokenPersistencePath()."/zcrm_oauthtokens.txt");
}

if ($content == "") {
$arr = array();
} else {
$arr = unserialize($content);
}
array_push($arr, $zohoOAuthTokens);
$serialized = serialize($arr);
file_put_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt",$serialized );
$result = file_put_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt",$serialized );

if ($result === false) {
throw new ZohoOAuthException("Can not write to tokens file, please check permissions: " . self::getTokenPersistencePath()."/zcrm_oauthtokens.txt");
}
} catch (Exception $ex) {
Logger::severe("Exception occured while Saving OAuthTokens to file(file::ZohoOAuthPersistenceByFile)({$ex->getMessage()})\n{$ex}");
throw $ex;
Expand All @@ -40,6 +49,11 @@ public function getOAuthTokens($userEmailId)
{
try {
$serialized = file_get_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt" );

if ($serialized === false) {
throw new ZohoOAuthException("Can not read tokens file, please check permissions: " . self::getTokenPersistencePath()."/zcrm_oauthtokens.txt");
}

if (! isset($serialized) || $serialized == "") {
throw new ZohoOAuthException("No Tokens exist for the given user-identifier,Please generate and try again.");
}
Expand Down