Skip to content

Commit 85cf0dc

Browse files
DonMartin76shockey
authored andcommitted
improve: include more error data from authorization call (via #4801)
* Additional fix of #4048, more error messages from authorization call Inspect the error and error_description properties of the response, if available * Fixed linter errors
1 parent c9e8a67 commit 85cf0dc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/core/plugins/auth/actions.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,28 @@ export const authorizeRequest = ( data ) => ( { fn, getConfigs, authActions, err
202202
})
203203
.catch(e => {
204204
let err = new Error(e)
205+
let message = err.message
206+
// swagger-js wraps the response (if available) into the e.response property;
207+
// investigate to check whether there are more details on why the authorization
208+
// request failed (according to RFC 6479).
209+
// See also https://github.com/swagger-api/swagger-ui/issues/4048
210+
if (e.response && e.response.data) {
211+
const errData = e.response.data
212+
try {
213+
const jsonResponse = typeof errData === "string" ? JSON.parse(errData) : errData
214+
if (jsonResponse.error)
215+
message += `, error: ${jsonResponse.error}`
216+
if (jsonResponse.error_description)
217+
message += `, description: ${jsonResponse.error_description}`
218+
} catch (jsonError) {
219+
// Ignore
220+
}
221+
}
205222
errActions.newAuthErr( {
206223
authId: name,
207224
level: "error",
208225
source: "auth",
209-
message: err.message
226+
message: message
210227
} )
211228
})
212229
}

0 commit comments

Comments
 (0)