fix: better error handling within parseCookies (#3720)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import type { Request } from 'express'
|
||||
|
||||
import { APIError } from '../errors'
|
||||
|
||||
export default function parseCookies(req: Request): { [key: string]: string } {
|
||||
const list = {}
|
||||
const rc = req.headers.cookie
|
||||
@@ -7,7 +9,15 @@ export default function parseCookies(req: Request): { [key: string]: string } {
|
||||
if (rc) {
|
||||
rc.split(';').forEach((cookie) => {
|
||||
const parts = cookie.split('=')
|
||||
list[parts.shift().trim()] = decodeURI(parts.join('='))
|
||||
const key = parts.shift().trim()
|
||||
const encodedValue = parts.join('=')
|
||||
|
||||
try {
|
||||
const decodedValue = decodeURI(encodedValue)
|
||||
list[key] = decodedValue
|
||||
} catch (e) {
|
||||
throw new APIError(`Error decoding cookie value for key ${key}: ${e.message}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user