Error

Raise SvelteKit HTTP errors as Effects inside remote handlers.

Error wraps SvelteKit's error helper as an Effect, so a handler can end a request with an HTTP error without leaving Effect control flow. The returned Effect never succeeds — SvelteKit takes over the request as soon as it runs.

Raise an HTTP error

posts.remote.ts
import { Error, Query } from "svelte-effect-runtime";
import { Effect, Schema } from "effect";

export const GetPost = Query(Schema.String, (id) =>
	Effect.gen(function* () {
		const post = yield* PostRepository.find(id);

		if (post === undefined) {
			return yield* Error("NotFound", "Post not found");
		}

		return post;
	}),
);

The status accepts a number or a PascalCase status name, so Error(404, ...) and Error("NotFound", ...) are equivalent.

Attach app error properties

SvelteKit 3 accepts extra properties next to a string message:

posts.remote.ts
return yield* Error("NotFound", "Post not found", {
	code: "POST_NOT_FOUND",
});
On this page