diff options
author | Ian Bull <irbull@eclipsesource.com> | 2024-09-18 18:19:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-18 18:19:45 -0700 |
commit | 282c4c262d3a19fe3ae3fd9ea75811b816e65dc1 (patch) | |
tree | 51ad919b29949215d5b9920097f04d24e062c4a7 /ext/http | |
parent | fd23e8ec4f815f273a348d528edbc3bf65a21b5f (diff) |
refactor(ext): align error messages (#25496)
Aligns the error messages in the ext/http and a few messages in the
ext/fetch folder to be in-line with the Deno style guide.
This change-set also removes some unnecessary checks in the 00_serve.ts.
These options were recently removed, so it doesn't make sense to check
for them anymore.
https://github.com/denoland/deno/issues/25269
Diffstat (limited to 'ext/http')
-rw-r--r-- | ext/http/00_serve.ts | 26 | ||||
-rw-r--r-- | ext/http/01_http.js | 6 |
2 files changed, 17 insertions, 15 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; diff --git a/ext/http/01_http.js b/ext/http/01_http.js index e88684858..9302bd8a0 100644 --- a/ext/http/01_http.js +++ b/ext/http/01_http.js @@ -207,7 +207,7 @@ function createRespondWith( resp = await resp; if (!(ObjectPrototypeIsPrototypeOf(ResponsePrototype, resp))) { throw new TypeError( - "First argument to respondWith must be a Response or a promise resolving to a Response.", + "First argument to 'respondWith' must be a Response or a promise resolving to a Response", ); } @@ -220,7 +220,7 @@ function createRespondWith( let respBody = null; if (innerResp.body !== null) { if (innerResp.body.unusable()) { - throw new TypeError("Body is unusable."); + throw new TypeError("Body is unusable"); } if ( ObjectPrototypeIsPrototypeOf( @@ -295,7 +295,7 @@ function createRespondWith( let reader; if (resourceBacking) { if (respBody.locked) { - throw new TypeError("ReadableStream is locked."); + throw new TypeError("ReadableStream is locked"); } reader = respBody.getReader(); // Acquire JS lock. try { |