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
This commit is contained in:
Ian Bull 2024-09-18 18:19:45 -07:00 committed by GitHub
parent fd23e8ec4f
commit 282c4c262d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 29 deletions

View file

@ -122,7 +122,7 @@ function newInnerRequest(method, url, headerList, body, maybeBlob) {
try {
this.headerListInner = headerList();
} catch {
throw new TypeError("cannot read headers: request closed");
throw new TypeError("Cannot read headers: request closed");
}
}
return this.headerListInner;
@ -153,7 +153,7 @@ function newInnerRequest(method, url, headerList, body, maybeBlob) {
try {
this.urlListProcessed[currentIndex] = this.urlList[currentIndex]();
} catch {
throw new TypeError("cannot read url: request closed");
throw new TypeError("Cannot read url: request closed");
}
}
return this.urlListProcessed[currentIndex];
@ -193,7 +193,7 @@ function cloneInnerRequest(request, skipBody = false) {
try {
this.urlListProcessed[0] = this.urlList[0]();
} catch {
throw new TypeError("cannot read url: request closed");
throw new TypeError("Cannot read url: request closed");
}
}
return this.urlListProcessed[0];
@ -204,7 +204,7 @@ function cloneInnerRequest(request, skipBody = false) {
try {
this.urlListProcessed[currentIndex] = this.urlList[currentIndex]();
} catch {
throw new TypeError("cannot read url: request closed");
throw new TypeError("Cannot read url: request closed");
}
}
return this.urlListProcessed[currentIndex];
@ -236,13 +236,13 @@ const KNOWN_METHODS = {
*/
function validateAndNormalizeMethod(m) {
if (RegExpPrototypeExec(HTTP_TOKEN_CODE_POINT_RE, m) === null) {
throw new TypeError("Method is not valid.");
throw new TypeError("Method is not valid");
}
const upperCase = byteUpperCase(m);
if (
upperCase === "CONNECT" || upperCase === "TRACE" || upperCase === "TRACK"
) {
throw new TypeError("Method is forbidden.");
throw new TypeError("Method is forbidden");
}
return upperCase;
}
@ -418,7 +418,7 @@ class Request {
((init.body !== undefined && init.body !== null) ||
inputBody !== null)
) {
throw new TypeError("Request with GET/HEAD method cannot have body.");
throw new TypeError("Request with GET/HEAD method cannot have body");
}
// 36.
@ -442,7 +442,7 @@ class Request {
// 41.
if (initBody === null && inputBody !== null) {
if (input[_body] && input[_body].unusable()) {
throw new TypeError("Input request's body is unusable.");
throw new TypeError("Input request's body is unusable");
}
finalBody = inputBody.createProxy();
}
@ -489,7 +489,7 @@ class Request {
const prefix = "Failed to execute 'Request.clone'";
webidl.assertBranded(this, RequestPrototype);
if (this[_body] && this[_body].unusable()) {
throw new TypeError("Body is unusable.");
throw new TypeError("Body is unusable");
}
const clonedReq = cloneInnerRequest(this[_request]);