diff options
author | Oliver Lenehan <sunsetkookaburra+github@outlook.com.au> | 2020-03-14 12:40:13 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-13 21:40:13 -0400 |
commit | 0f6acf275370cae09ffb3f6950a3926424f3b024 (patch) | |
tree | e77a2115394f36dcbd899fd8f2d5496ca7bde625 /std/textproto/mod.ts | |
parent | aab1acaed163f91aa5e89b079c5312336abb2088 (diff) |
fix(std): Use Deno.errors where possible. (#4356)
Diffstat (limited to 'std/textproto/mod.ts')
-rw-r--r-- | std/textproto/mod.ts | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/std/textproto/mod.ts b/std/textproto/mod.ts index dd7d3ede9..b27b1d59b 100644 --- a/std/textproto/mod.ts +++ b/std/textproto/mod.ts @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -import { BufReader, UnexpectedEOFError } from "../io/bufio.ts"; +import { BufReader } from "../io/bufio.ts"; import { charCode } from "../io/util.ts"; const asciiDecoder = new TextDecoder(); @@ -15,13 +15,6 @@ function str(buf: Uint8Array | null | undefined): string { } } -export class ProtocolError extends Error { - constructor(msg: string) { - super(msg); - this.name = "ProtocolError"; - } -} - export function append(a: Uint8Array, b: Uint8Array): Uint8Array { if (a == null) { return b; @@ -79,16 +72,16 @@ export class TextProtoReader { buf = await this.r.peek(1); if (buf === Deno.EOF) { - throw new UnexpectedEOFError(); + throw new Deno.errors.UnexpectedEof(); } else if (buf[0] == charCode(" ") || buf[0] == charCode("\t")) { - throw new ProtocolError( + throw new Deno.errors.InvalidData( `malformed MIME header initial line: ${str(line)}` ); } while (true) { const kv = await this.readLineSlice(); // readContinuedLineSlice - if (kv === Deno.EOF) throw new UnexpectedEOFError(); + if (kv === Deno.EOF) throw new Deno.errors.UnexpectedEof(); if (kv.byteLength === 0) return m; // Key ends at first colon; should not have trailing spaces @@ -96,7 +89,9 @@ export class TextProtoReader { // them if present. let i = kv.indexOf(charCode(":")); if (i < 0) { - throw new ProtocolError(`malformed MIME header line: ${str(kv)}`); + throw new Deno.errors.InvalidData( + `malformed MIME header line: ${str(kv)}` + ); } let endKey = i; while (endKey > 0 && kv[endKey - 1] == charCode(" ")) { @@ -108,7 +103,7 @@ export class TextProtoReader { // As per RFC 7230 field-name is a token, // tokens consist of one or more chars. - // We could return a ProtocolError here, + // We could throw `Deno.errors.InvalidData` here, // but better to be liberal in what we // accept, so if we get an empty key, skip it. if (key == "") { |