22 lines
518 B
TypeScript
22 lines
518 B
TypeScript
import { Data } from "effect";
|
|
|
|
export class RequestError extends Data.TaggedError("RequestError")<{
|
|
readonly status: number,
|
|
readonly body?: string,
|
|
}> {
|
|
get response(): Response {
|
|
if (this.body) {
|
|
const body = new TextEncoder().encode(this.body);
|
|
return new Response(body, {
|
|
headers: {
|
|
"Content-Length": body.byteLength.toString(),
|
|
"Content-Type": "text/plain; charset=utf-8",
|
|
},
|
|
status: this.status,
|
|
});
|
|
} else {
|
|
return new Response(null, { status: this.status });
|
|
}
|
|
}
|
|
}
|