better logging for moodle access
This commit is contained in:
parent
1dadca2eae
commit
40b0426129
1 changed files with 38 additions and 17 deletions
|
@ -336,27 +336,48 @@ class MoodleRestTemplateFactory {
|
|||
|
||||
private void requestAccessToken() {
|
||||
|
||||
final ResponseEntity<String> response = super.exchange(
|
||||
this.serverURL + this.tokenPath,
|
||||
HttpMethod.GET,
|
||||
this.tokenReqEntity,
|
||||
String.class,
|
||||
this.tokenReqURIVars);
|
||||
|
||||
if (response.getStatusCode() != HttpStatus.OK) {
|
||||
throw new RuntimeException("Failed to gain access token for LMS (Moodle): lmsSetup: " +
|
||||
MoodleRestTemplateFactory.this.lmsSetup + " response: " + response.getBody());
|
||||
}
|
||||
|
||||
try {
|
||||
final MoodleToken moodleToken = MoodleRestTemplateFactory.this.jsonMapper.readValue(
|
||||
response.getBody(),
|
||||
MoodleToken.class);
|
||||
final ResponseEntity<String> response = super.exchange(
|
||||
this.serverURL + this.tokenPath,
|
||||
HttpMethod.GET,
|
||||
this.tokenReqEntity,
|
||||
String.class,
|
||||
this.tokenReqURIVars);
|
||||
|
||||
if (response.getStatusCode() != HttpStatus.OK) {
|
||||
log.error("Failed to gain access token for LMS (Moodle): lmsSetup: {} response: {} : {}",
|
||||
MoodleRestTemplateFactory.this.lmsSetup,
|
||||
response.getStatusCode(),
|
||||
response.getBody());
|
||||
throw new RuntimeException("Failed to gain access token for LMS (Moodle): lmsSetup: " +
|
||||
MoodleRestTemplateFactory.this.lmsSetup + " response: " + response.getBody());
|
||||
}
|
||||
|
||||
try {
|
||||
final MoodleToken moodleToken = MoodleRestTemplateFactory.this.jsonMapper.readValue(
|
||||
response.getBody(),
|
||||
MoodleToken.class);
|
||||
|
||||
if (moodleToken == null || moodleToken.token == null) {
|
||||
throw new RuntimeException("Access Token request with 200 but no or invalid token body");
|
||||
}
|
||||
|
||||
this.accessToken = moodleToken.token;
|
||||
} catch (final Exception e) {
|
||||
log.error("Failed to gain access token for LMS (Moodle): lmsSetup: {} response: {} : {}",
|
||||
MoodleRestTemplateFactory.this.lmsSetup,
|
||||
response.getStatusCode(),
|
||||
response.getBody());
|
||||
throw new RuntimeException("Failed to gain access token for LMS (Moodle): lmsSetup: " +
|
||||
MoodleRestTemplateFactory.this.lmsSetup + " response: " + response.getBody(), e);
|
||||
}
|
||||
|
||||
this.accessToken = moodleToken.token;
|
||||
} catch (final Exception e) {
|
||||
log.error("Failed to gain access token for LMS (Moodle): lmsSetup: {} :",
|
||||
MoodleRestTemplateFactory.this.lmsSetup,
|
||||
e);
|
||||
throw new RuntimeException("Failed to gain access token for LMS (Moodle): lmsSetup: " +
|
||||
MoodleRestTemplateFactory.this.lmsSetup + " response: " + response.getBody(), e);
|
||||
MoodleRestTemplateFactory.this.lmsSetup + " cause: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue