mirror of
https://github.com/skidoodle/erettsegi-browser.git
synced 2025-02-15 05:39:15 +01:00
better api error handling?!
This commit is contained in:
parent
43d51f172a
commit
31ebb3d694
1 changed files with 30 additions and 5 deletions
|
@ -7,7 +7,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const missingParams = []
|
const missingParams = []
|
||||||
if (!ev) missingParams.push('ev')
|
if (!ev) missingParams.push('ev')
|
||||||
if (!szint) missingParams.push('szint')
|
if (!szint) missingParams.push('szint')
|
||||||
if (!idoszak) missingParams.push('evszak')
|
if (!idoszak) missingParams.push('idoszak')
|
||||||
if (!vizsgatargy) missingParams.push('vizsgatargy')
|
if (!vizsgatargy) missingParams.push('vizsgatargy')
|
||||||
if (!tipus) missingParams.push('tipus')
|
if (!tipus) missingParams.push('tipus')
|
||||||
|
|
||||||
|
@ -17,6 +17,31 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
.json({ error: `Hiányzó paraméterek: ${missingParams.join(', ')}` })
|
.json({ error: `Hiányzó paraméterek: ${missingParams.join(', ')}` })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ev! <= '2005') {
|
||||||
|
return res.status(400).json({ error: 'Érvénytelen év' })
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (vizsgatargy) {
|
||||||
|
case 'magyir':
|
||||||
|
case 'mat':
|
||||||
|
case 'tort':
|
||||||
|
case 'angol':
|
||||||
|
case 'nemet':
|
||||||
|
case 'inf':
|
||||||
|
case 'infoism':
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return res.status(400).json({ error: 'Érvénytelen vizsgatárgy' })
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (tipus) {
|
||||||
|
case 'fl':
|
||||||
|
case 'ut':
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return res.status(400).json({ error: 'Érvénytelen típus' })
|
||||||
|
}
|
||||||
|
|
||||||
let honap
|
let honap
|
||||||
switch (idoszak) {
|
switch (idoszak) {
|
||||||
case 'osz':
|
case 'osz':
|
||||||
|
@ -26,7 +51,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
honap = 'maj'
|
honap = 'maj'
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return res.status(400).json({ error: 'Érvénytelen évszak' })
|
return res.status(400).json({ error: 'Érvénytelen időszak' })
|
||||||
}
|
}
|
||||||
|
|
||||||
let prefix
|
let prefix
|
||||||
|
@ -61,7 +86,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
pdfUrl = `${baseUrl}${ev}${idoszak}_${szint}/${prefix}_${shortev}${honap}_${tipus}.pdf`
|
pdfUrl = `${baseUrl}${ev}${idoszak}_${szint}/${prefix}_${shortev}${honap}_${tipus}.pdf`
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return res.status(400).json({ error: 'Érvénytelen fájltípus' })
|
return res.status(400).json({ error: 'Érvénytelen fájl' })
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'megoldas':
|
case 'megoldas':
|
||||||
|
@ -75,11 +100,11 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
pdfUrl = `${baseUrl}${ev}${idoszak}_${szint}/${prefix}_${shortev}${honap}_${tipus}.pdf`
|
pdfUrl = `${baseUrl}${ev}${idoszak}_${szint}/${prefix}_${shortev}${honap}_${tipus}.pdf`
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return res.status(400).json({ error: 'Érvénytelen fájltípus' })
|
return res.status(400).json({ error: 'Érvénytelen fájl' })
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return res.status(400).json({ error: 'Érvénytelen fájltípus' })
|
return res.status(400).json({ error: 'Érvénytelen fájl' })
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue