Back to Withastro

The middleware didn't return a Response.

src/content/docs/en/reference/errors/middleware-no-data-or-next-called.mdx

latest577 B
Original Source

import DontEditWarning from '~/components/DontEditWarning.astro'

<DontEditWarning />

MiddlewareNoDataOrNextCalled: Make sure your middleware returns a Response object, either directly or by returning the Response from calling the next function.

What went wrong?

Thrown when the middleware does not return any data or call the next function.

For example:

ts
import {defineMiddleware} from "astro:middleware";
export const onRequest = defineMiddleware((context, _) => {
	// doesn't return anything or call `next`
	context.locals.someData = false;
});