Skip to content

Commit fc9d6fb

Browse files
committed
[server] Log response status when GitHub Education API calls fail
1 parent c566c5b commit fc9d6fb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

components/server/ee/src/user/eligibility-service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,26 @@ export class EligibilityService {
9393
return { student: false, faculty: false };
9494
}
9595

96+
const logCtx = { userId: user.id };
9697
try {
9798
const rawResponse = await fetch("https://education.github.com/api/user", {
9899
headers: {
99100
"Authorization": `token ${token}`,
100101
"faculty-check-preview": "true"
101102
}
102103
});
104+
if (!rawResponse.ok) {
105+
log.warn(logCtx, `fetching the GitHub Education API failed with status ${rawResponse.status}: ${rawResponse.statusText}`);
106+
}
103107
const result : GitHubEducationPack = JSON.parse(await rawResponse.text());
104108
if(result.student && result.faculty) {
105109
// That violates the API contract: `student` and `faculty` need to be mutually exclusive
106-
log.warn({userId: user.id}, "result of GitHub Eduction API violates the API contract: student and faculty need to be mutually exclusive", result);
110+
log.warn(logCtx, "result of GitHub Eduction API violates the API contract: student and faculty need to be mutually exclusive", result);
107111
return { student: false, faculty: false };
108112
}
109113
return result;
110114
} catch (err) {
111-
log.warn({ userId: user.id }, "error while checking student pack status", err);
115+
log.warn(logCtx, "error while checking student pack status", err);
112116
}
113117
return { student: false, faculty: false };
114118
}

0 commit comments

Comments
 (0)