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

more informative error message #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
.npmrc
*.tgz
.idea/
12 changes: 11 additions & 1 deletion src/Strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ export class Strategy<TUser = object, TInfo = object> extends OAuth2Strategy {
this._oauth2.useAuthorizationHeaderforGET(true);
this._oauth2.get("https://www.patreon.com/api/oauth2/v2/identity?fields[user]=" + this.fields.join(","), accessToken, (error, result) => {

if (error) return done(new InternalOAuthError("Failed to fetch user profile", error));
if (error) {
let errorStr;
try {
const errors = JSON.parse(error.data);
errorStr = '\n' + errors.errors.map((x: any) => `${x.code_name}: ${x.detail}`).join('\n ');
}
catch (parseError) {
errorStr = '';
}
return done(new InternalOAuthError(`Failed to fetch user profile${errorStr}`, error));
}

let json: UserResponse;

Expand Down