Skip to content

Commit

Permalink
chore: do not spawn errors on extensions page
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Jun 21, 2024
1 parent c2b3e05 commit 2c8a090
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/features/autologin/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export async function autoLogIn() {
console.debug('Auto logging in...')
const privateToken = await getStored('privateToken')
if (!privateToken) {
console.error('No private token found')
console.log('Warning: No private token found')
return false
}

const userId = await getStored('userId')
if (!userId) {
console.error('No user ID found')
console.log('Warning: No user ID found')
return false
}

Expand All @@ -30,7 +30,7 @@ export async function autoLogIn() {
return true
}
catch (e) {
console.error('Auto login failed', e)
console.log('Warning: Auto login failed', e)
return false
}
}
15 changes: 10 additions & 5 deletions src/features/courses/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ export async function fetchCourses(force: boolean = false) {
}

console.log('Fetching courses')
const { courses } = await moodle.core.course.getEnrolledCoursesByTimelineClassification({
classification: 'inprogress',
})
await setStored('courses', courses)
await setStored('coursesLastUpdateMS', Date.now())
try {
const { courses } = await moodle.core.course.getEnrolledCoursesByTimelineClassification({
classification: 'inprogress',
})
await setStored('courses', courses)
await setStored('coursesLastUpdateMS', Date.now())
}
catch (e) {
console.log('Error: Couldn\'t fetch courses')
}
}
14 changes: 12 additions & 2 deletions src/shared/moodle-ws-api/token-for-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,22 @@ export async function obtainMobileToken(options: { useSSO?: boolean } = { useSSO
const plainToken = atob(encodedToken)
const [_, token, privateToken] = plainToken.split(':::') as [string, string, string | undefined]

if (token === undefined) {
console.log('Warning: Couldn\'t get mobile_app token')
}
else if (privateToken === undefined) {
console.log('Warning: Got token, but no privateToken')
}
else {
console.log('Got token and privateToken')
}

return { token, privateToken }
}
catch (e) {
console.error('Couldn\'t get mobile_app token')
console.log('Warning: Couldn\'t get mobile_app token')
if (options.useSSO) {
console.error('Trying without SSO...')
console.log('Warning: Trying without SSO...')
return await obtainMobileToken({ useSSO: false })
}
}
Expand Down

0 comments on commit 2c8a090

Please # to comment.