Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 6262d88

Browse files
Fix issue where getting single record did not work properly
1 parent 0571437 commit 6262d88

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/common/helper.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,24 @@ async function getUbahnSingleRecord (path, params, isOptionRecord) {
106106
logger.debug(`request GET ${path} by params: ${JSON.stringify(params)}`)
107107
try {
108108
const res = await axios.get(`${config.UBAHN_API_URL}${path}`, { headers: { Authorization: `Bearer ${token}` }, params })
109-
if (res.data.length === 1) {
110-
return res.data[0]
111-
}
112-
if (res.data.length === 0 && isOptionRecord) {
113-
return null
114-
}
115-
if (res.data.length > 1) {
116-
const record = _.find(res.data, params)
117-
118-
if (!record) {
119-
throw Error('Multiple records returned. None exactly match query')
109+
if (_.isArray(res.data)) {
110+
if (res.data.length === 1) {
111+
return res.data[0]
120112
}
113+
if (res.data.length === 0 && isOptionRecord) {
114+
return null
115+
}
116+
if (res.data.length > 1) {
117+
const record = _.find(res.data, params)
118+
119+
if (!record) {
120+
throw Error('Multiple records returned. None exactly match query')
121+
}
121122

122-
return record
123+
return record
124+
}
125+
} else {
126+
return res.data
123127
}
124128
} catch (err) {
125129
logger.error(`get ${path} by params: ${JSON.stringify(params)} failed`)

0 commit comments

Comments
 (0)