Skip to content

Commit

Permalink
fix(website): error handling middleware
Browse files Browse the repository at this point in the history
 * configure dev flow properly
  • Loading branch information
TobiasKampmann committed Jan 10, 2024
1 parent 064438e commit 71337ed
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/node_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
env:
CONFIG_DIR: ./tests/config
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Generate local test config
run: ./generate_local_test_config.sh

- name: Install dependencies
working-directory: website
Expand Down
3 changes: 2 additions & 1 deletion website/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sequence } from 'astro:middleware';

import { authMiddleware } from './middleware/authMiddleware.ts';
import { catchErrorMiddleware } from './middleware/catchErrorMiddleware.ts';
import { organismValidatorMiddleware } from './middleware/organismValidatorMiddleware.ts';

export const onRequest = sequence(organismValidatorMiddleware, authMiddleware);
export const onRequest = sequence(catchErrorMiddleware, organismValidatorMiddleware, authMiddleware);
14 changes: 14 additions & 0 deletions website/src/middleware/catchErrorMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineMiddleware } from 'astro/middleware';

import { getInstanceLogger } from '../logger.ts';

const logger = getInstanceLogger('ErrorMiddleware');

export const catchErrorMiddleware = defineMiddleware(async (context, next) => {
try {
return next();
} catch (error) {
logger.error(`Error for path (${context.url.pathname}): ${error}`);
return context.redirect('/500');
}
});
1 change: 1 addition & 0 deletions website/src/utils/isPublicRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function getPublicRoutes(configuredOrganisms: string[]) {
publicRoutesCache[cacheKey] = [
new RegExp('^/?$'),
new RegExp('^/404$'),
new RegExp('^/500$'),
new RegExp('^/about$'),
new RegExp('^/api_documentation$'),
new RegExp('^/governance$'),
Expand Down

0 comments on commit 71337ed

Please sign in to comment.