From 4e3f2c7615a5dd07b17fdf95cc0c23ca9d8e8b60 Mon Sep 17 00:00:00 2001 From: Tom Shortall Date: Fri, 17 Apr 2020 18:03:29 +0100 Subject: [PATCH] more informative error message --- .gitignore | 1 + src/Strategy.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9aa494e..59bf0e0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules dist .npmrc *.tgz +.idea/ diff --git a/src/Strategy.ts b/src/Strategy.ts index 1f951e6..d12c3b9 100644 --- a/src/Strategy.ts +++ b/src/Strategy.ts @@ -80,7 +80,17 @@ export class Strategy 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;