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 0917e82
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions server/apiCalls/kursinfoApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,24 @@ 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: { sv: '', en: '' },
imageInfo: '',
supplementaryInfo: { sv: '', en: '' },
courseDisposition: { sv: '', en: '' },
}
return { 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 defaultValues
} catch (err) {
log.error('Kursinfo-api is not available', err)
return err
Expand Down

0 comments on commit 0917e82

Please sign in to comment.