summaryrefslogtreecommitdiff
path: root/ext/http/00_serve.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ext/http/00_serve.ts')
-rw-r--r--ext/http/00_serve.ts26
1 files changed, 14 insertions, 12 deletions
diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts
index 6d23685d8..3b9b085a2 100644
--- a/ext/http/00_serve.ts
+++ b/ext/http/00_serve.ts
@@ -123,7 +123,7 @@ function upgradeHttpRaw(req, conn) {
if (inner._wantsUpgrade) {
return inner._wantsUpgrade("upgradeHttpRaw", conn);
}
- throw new TypeError("upgradeHttpRaw may only be used with Deno.serve");
+ throw new TypeError("'upgradeHttpRaw' may only be used with Deno.serve");
}
function addTrailers(resp, headerList) {
@@ -170,10 +170,10 @@ class InnerRequest {
_wantsUpgrade(upgradeType, ...originalArgs) {
if (this.#upgraded) {
- throw new Deno.errors.Http("already upgraded");
+ throw new Deno.errors.Http("Already upgraded");
}
if (this.#external === null) {
- throw new Deno.errors.Http("already closed");
+ throw new Deno.errors.Http("Already closed");
}
// upgradeHttpRaw is sync
@@ -257,7 +257,7 @@ class InnerRequest {
if (this.#methodAndUri === undefined) {
if (this.#external === null) {
- throw new TypeError("request closed");
+ throw new TypeError("Request closed");
}
// TODO(mmastrac): This is quite slow as we're serializing a large number of values. We may want to consider
// splitting this up into multiple ops.
@@ -315,7 +315,7 @@ class InnerRequest {
}
if (this.#methodAndUri === undefined) {
if (this.#external === null) {
- throw new TypeError("request closed");
+ throw new TypeError("Request closed");
}
this.#methodAndUri = op_http_get_request_method_and_url(this.#external);
}
@@ -329,7 +329,7 @@ class InnerRequest {
get method() {
if (this.#methodAndUri === undefined) {
if (this.#external === null) {
- throw new TypeError("request closed");
+ throw new TypeError("Request closed");
}
this.#methodAndUri = op_http_get_request_method_and_url(this.#external);
}
@@ -338,7 +338,7 @@ class InnerRequest {
get body() {
if (this.#external === null) {
- throw new TypeError("request closed");
+ throw new TypeError("Request closed");
}
if (this.#body !== undefined) {
return this.#body;
@@ -356,7 +356,7 @@ class InnerRequest {
get headerList() {
if (this.#external === null) {
- throw new TypeError("request closed");
+ throw new TypeError("Request closed");
}
const headers = [];
const reqHeaders = op_http_get_request_headers(this.#external);
@@ -457,7 +457,7 @@ function fastSyncResponseOrStream(
// At this point in the response it needs to be a stream
if (!ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, stream)) {
innerRequest?.close();
- throw new TypeError("invalid response");
+ throw new TypeError("Invalid response");
}
const resourceBacking = getReadableStreamResourceBacking(stream);
let rid, autoClose;
@@ -619,13 +619,15 @@ function serve(arg1, arg2) {
if (handler === undefined) {
if (options === undefined) {
throw new TypeError(
- "No handler was provided, so an options bag is mandatory.",
+ "Cannot serve HTTP requests: either a `handler` or `options` must be specified",
);
}
handler = options.handler;
}
if (typeof handler !== "function") {
- throw new TypeError("A handler function must be provided.");
+ throw new TypeError(
+ `Cannot serve HTTP requests: handler must be a function, received ${typeof handler}`,
+ );
}
if (options === undefined) {
options = { __proto__: null };
@@ -679,7 +681,7 @@ function serve(arg1, arg2) {
if (wantsHttps) {
if (!options.cert || !options.key) {
throw new TypeError(
- "Both cert and key must be provided to enable HTTPS.",
+ "Both 'cert' and 'key' must be provided to enable HTTPS",
);
}
listenOpts.cert = options.cert;