| 384 | * Typed error for an unsupported or failed in-place TLS upgrade. |
| 385 | * |
| 386 | * @category errors |
| 387 | * @since 4.0.0 |
| 388 | */ |
| 389 | export class SocketUpgradeError extends Schema.Error<SocketUpgradeError>( |
| 390 | "effect/socket/Socket/SocketUpgradeError" |
| 391 | )({ |
| 392 | _tag: Schema.tag("SocketUpgradeError"), |
| 393 | cause: Schema.optional(Schema.Defect()) |
| 394 | }) { |
| 395 | /** |
| 396 | * An upgrade implementation for transports that cannot wrap the connection |
| 397 | * with TLS. |
| 398 | * |
| 399 | * @since 4.0.0 |
| 400 | */ |
| 401 | static readonly unsupported: Reader["upgrade"] = () => |
| 402 | Effect.fail(new SocketError({ reason: new SocketUpgradeError({}) })) |
| 403 | |
| 404 | override get message() { |
| 405 | return this.cause === undefined |
| 406 | ? `Socket does not support TLS upgrade` |
| 407 | : `An error occurred during TLS upgrade` |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Typed error for a socket close, carrying the close code and optional close |
| 413 | * reason. |
| 414 | * |
| 415 | * **Details** |
| 416 | * |
| 417 | * Sockets never classify closes: any close, whatever the code, fails the |
| 418 | * reader with a `SocketError` wrapping this reason. Consumers that treat a |
| 419 | * close as normal catch it. |
| 420 | * |
| 421 | * @category errors |
| 422 | * @since 4.0.0 |
| 423 | */ |
| 424 | export class SocketCloseError extends Schema.Error<SocketCloseError>("effect/socket/Socket/SocketCloseError")({ |
| 425 | _tag: Schema.tag("SocketCloseError"), |
| 426 | code: Schema.Int, |
| 427 | closeReason: Schema.optional(Schema.String) |
| 428 | }) { |
| 429 | override get message() { |
| 430 | if (this.closeReason) { |
| 431 | return `${this.code}: ${this.closeReason}` |
| 432 | } |
| 433 | return `${this.code}` |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Schema for all socket-specific error reasons. |