Skip to content

Commit

Permalink
Return 400 (not 500) on invalid short redir URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Nov 19, 2024
1 parent fa14861 commit 107308c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/shortUrlRedir.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {basename, dirname} from 'node:path';
import {HebrewCalendar, parshiot} from '@hebcal/core';
import {getSedra, parshiot} from '@hebcal/core';
import {makeAnchor} from '@hebcal/rest-api';
import dayjs from 'dayjs';

Expand Down Expand Up @@ -97,8 +97,11 @@ function shortParshaRedir(ctx, str, qs) {
}
const yearStr = dirname(str);
const year = parseInt(yearStr, 10);
if (!year) {
ctx.throw(400, `invalid short redirect parsha: ${str}`);
}
const il = yearStr.endsWith('i');
const sedra = HebrewCalendar.getSedra(year, il);
const sedra = getSedra(year, il);
const hd = sedra.find(doubled ? -parshaId : parshaId);
if (hd === null) {
ctx.throw(404, `short redirect not found: ${str}`);
Expand Down

0 comments on commit 107308c

Please sign in to comment.