Skip to content

Commit

Permalink
Propagate errors correctly for static Reddit create methods (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonyi authored Sep 24, 2018
1 parent 429bd8c commit 3bdb67a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/src/reddit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,10 @@ class Reddit {
final grant = new oauth2.AuthorizationCodeGrant(_config.clientId,
Uri.parse(_config.authorizeUrl), Uri.parse(_config.accessToken),
secret: _config.clientSecret);

ReadOnlyAuthenticator.create(_config, grant).then(_initializationCallback);
_readOnly = true;
ReadOnlyAuthenticator.create(_config, grant)
.then(_initializationCallback)
.catchError(_initializationError);
}

Reddit._untrustedReadOnlyInstance(
Expand Down Expand Up @@ -366,9 +367,10 @@ class Reddit {
Uri.parse(_config.accessToken), Uri.parse(_config.accessToken),
secret: null);

ReadOnlyAuthenticator.createUntrusted(_config, grant, deviceId)
.then(_initializationCallback);
_readOnly = true;
ReadOnlyAuthenticator.createUntrusted(_config, grant, deviceId)
.then(_initializationCallback)
.catchError(_initializationError);
}

Reddit._scriptInstance(
Expand Down Expand Up @@ -407,8 +409,10 @@ class Reddit {
Uri.parse(_config.authorizeUrl), Uri.parse(_config.accessToken),
secret: _config.clientSecret);

ScriptAuthenticator.create(_config, grant).then(_initializationCallback);
_readOnly = false;
ScriptAuthenticator.create(_config, grant)
.then(_initializationCallback)
.catchError(_initializationError);
}

Reddit._webFlowInstance(
Expand Down Expand Up @@ -592,4 +596,9 @@ class Reddit {
_initialized = true;
_initializedCompleter.complete(true);
}

void _initializationError(e) {
_initialized = false;
_initializedCompleter.completeError(e);
}
}

0 comments on commit 3bdb67a

Please sign in to comment.