From c0a4efdce22a26631d381847e64cd883b98feb83 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Mon, 1 May 2017 10:48:06 +0800 Subject: [PATCH] MDL-58535 repository_onedrive: Better error When OneDrive has never been initialised the Graph API returns an error. Detect this and direct the user to log in to OneDrive. --- repository/onedrive/lang/en/repository_onedrive.php | 1 + repository/onedrive/lib.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/repository/onedrive/lang/en/repository_onedrive.php b/repository/onedrive/lang/en/repository_onedrive.php index 4227e146fd7..e97eb850c2e 100644 --- a/repository/onedrive/lang/en/repository_onedrive.php +++ b/repository/onedrive/lang/en/repository_onedrive.php @@ -34,6 +34,7 @@ $string['importskydrivefiles'] = 'Import files from Microsoft SkyDrive repositor $string['internal'] = 'Internal (files stored in Moodle)'; $string['issuer_help'] = 'Select the OAuth 2 service that is configured to talk to the OneDrive API. If the services does not exist yet, you might need to create it.'; $string['issuer'] = 'OAuth 2 service'; +$string['mysitenotfound'] = 'You have never logged into OneDrive before. You must login to OneDrive at least once it before it can be used with Moodle.'; $string['oauth2serviceslink'] = 'OAuth 2 Services Configuration'; $string['owner'] = 'Owned by: {$a}'; $string['pluginname'] = 'Microsoft OneDrive'; diff --git a/repository/onedrive/lib.php b/repository/onedrive/lib.php index 506289ec0a7..849013a74bd 100644 --- a/repository/onedrive/lib.php +++ b/repository/onedrive/lib.php @@ -311,8 +311,8 @@ class repository_onedrive extends repository { } catch (Exception $e) { if ($e->getCode() == 403 && strpos($e->getMessage(), 'Access Not Configured') !== false) { throw new repository_exception('servicenotenabled', 'repository_onedrive'); - } else { - throw $e; + } else if (strpos($e->getMessage(), 'mysite not found') !== false) { + throw new repository_exception('mysitenotfound', 'repository_onedrive'); } }