Skip to content

Commit

Permalink
fix(KUI-1207): fix call to getCourseInfo
Browse files Browse the repository at this point in the history
Only look at body if statusCode is 200/OK, otherwise return default values
  • Loading branch information
belanglos committed Feb 29, 2024
1 parent e7d7bf5 commit 4298938
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions server/apiCalls/kursinfoApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ async function _getCourseInfo(courseCode) {
const uri = client.resolve(paths.getCourseInfoByCourseCode.uri, { courseCode })
const res = await client.getAsync({ uri }, { useCache: false })

if (res.body) {
const { sellingText, courseDisposition, supplementaryInfo, imageInfo } = res.body
return { sellingText, courseDisposition, supplementaryInfo, imageInfo }
const defaultValues = { sellingText: {}, imageInfo: '', supplementaryInfo: {}, courseDisposition: {} }

if (res.statusCode === 200 && res.body) {
const { body } = res
return {
sellingText: body.sellingText ?? defaultValues.sellingText,
courseDisposition: body.courseDisposition ?? defaultValues.courseDisposition,
supplementaryInfo: body.supplementaryInfo ?? defaultValues.supplementaryInfo,
imageInfo: body.imageInfo ?? defaultValues.imageInfo,
}
}
return { sellingText: {}, imageInfo: '', supplementaryInfo: {}, courseDisposition: {} }

return defaultValues
} catch (err) {
log.error('Kursinfo-api is not available', err)
return err
Expand Down

0 comments on commit 4298938

Please sign in to comment.