@effect/platform 0.47.0 → 0.47.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/cjs/Error.js +40 -4
  2. package/dist/cjs/Error.js.map +1 -1
  3. package/dist/cjs/Http/Body.js +8 -1
  4. package/dist/cjs/Http/Body.js.map +1 -1
  5. package/dist/cjs/Http/ClientError.js +21 -2
  6. package/dist/cjs/Http/ClientError.js.map +1 -1
  7. package/dist/cjs/Http/Headers.js +22 -1
  8. package/dist/cjs/Http/Headers.js.map +1 -1
  9. package/dist/cjs/Http/ServerError.js +30 -7
  10. package/dist/cjs/Http/ServerError.js.map +1 -1
  11. package/dist/cjs/Http/UrlParams.js +7 -2
  12. package/dist/cjs/Http/UrlParams.js.map +1 -1
  13. package/dist/cjs/PlatformLogger.js +1 -1
  14. package/dist/cjs/internal/http/body.js +1 -1
  15. package/dist/cjs/internal/http/body.js.map +1 -1
  16. package/dist/cjs/internal/http/client.js +5 -5
  17. package/dist/cjs/internal/http/client.js.map +1 -1
  18. package/dist/cjs/internal/http/clientError.js +1 -36
  19. package/dist/cjs/internal/http/clientError.js.map +1 -1
  20. package/dist/cjs/internal/http/clientResponse.js +8 -8
  21. package/dist/cjs/internal/http/clientResponse.js.map +1 -1
  22. package/dist/cjs/internal/http/multiplex.js +1 -1
  23. package/dist/cjs/internal/http/multiplex.js.map +1 -1
  24. package/dist/cjs/internal/http/router.js +1 -1
  25. package/dist/cjs/internal/http/router.js.map +1 -1
  26. package/dist/cjs/internal/http/serverError.js +1 -15
  27. package/dist/cjs/internal/http/serverError.js.map +1 -1
  28. package/dist/cjs/internal/http/serverRequest.js +8 -8
  29. package/dist/cjs/internal/http/serverRequest.js.map +1 -1
  30. package/dist/dts/Error.d.ts +22 -0
  31. package/dist/dts/Error.d.ts.map +1 -1
  32. package/dist/dts/Http/Body.d.ts +9 -1
  33. package/dist/dts/Http/Body.d.ts.map +1 -1
  34. package/dist/dts/Http/ClientError.d.ts +21 -33
  35. package/dist/dts/Http/ClientError.d.ts.map +1 -1
  36. package/dist/dts/Http/Headers.d.ts +19 -0
  37. package/dist/dts/Http/Headers.d.ts.map +1 -1
  38. package/dist/dts/Http/ServerError.d.ts +33 -47
  39. package/dist/dts/Http/ServerError.d.ts.map +1 -1
  40. package/dist/dts/Http/UrlParams.d.ts +5 -0
  41. package/dist/dts/Http/UrlParams.d.ts.map +1 -1
  42. package/dist/dts/PlatformLogger.d.ts +1 -1
  43. package/dist/esm/Error.js +38 -3
  44. package/dist/esm/Error.js.map +1 -1
  45. package/dist/esm/Http/Body.js +6 -0
  46. package/dist/esm/Http/Body.js.map +1 -1
  47. package/dist/esm/Http/ClientError.js +19 -2
  48. package/dist/esm/Http/ClientError.js.map +1 -1
  49. package/dist/esm/Http/Headers.js +21 -1
  50. package/dist/esm/Http/Headers.js.map +1 -1
  51. package/dist/esm/Http/ServerError.js +26 -7
  52. package/dist/esm/Http/ServerError.js.map +1 -1
  53. package/dist/esm/Http/UrlParams.js +5 -0
  54. package/dist/esm/Http/UrlParams.js.map +1 -1
  55. package/dist/esm/PlatformLogger.js +1 -1
  56. package/dist/esm/internal/http/body.js +1 -1
  57. package/dist/esm/internal/http/body.js.map +1 -1
  58. package/dist/esm/internal/http/client.js +5 -5
  59. package/dist/esm/internal/http/client.js.map +1 -1
  60. package/dist/esm/internal/http/clientError.js +0 -10
  61. package/dist/esm/internal/http/clientError.js.map +1 -1
  62. package/dist/esm/internal/http/clientResponse.js +8 -8
  63. package/dist/esm/internal/http/clientResponse.js.map +1 -1
  64. package/dist/esm/internal/http/multiplex.js +1 -1
  65. package/dist/esm/internal/http/multiplex.js.map +1 -1
  66. package/dist/esm/internal/http/router.js +1 -1
  67. package/dist/esm/internal/http/router.js.map +1 -1
  68. package/dist/esm/internal/http/serverError.js +0 -14
  69. package/dist/esm/internal/http/serverError.js.map +1 -1
  70. package/dist/esm/internal/http/serverRequest.js +8 -8
  71. package/dist/esm/internal/http/serverRequest.js.map +1 -1
  72. package/package.json +3 -3
  73. package/src/Error.ts +61 -0
  74. package/src/Http/Body.ts +14 -1
  75. package/src/Http/ClientError.ts +21 -38
  76. package/src/Http/Headers.ts +29 -1
  77. package/src/Http/ServerError.ts +25 -56
  78. package/src/Http/UrlParams.ts +10 -0
  79. package/src/PlatformLogger.ts +1 -1
  80. package/src/internal/http/body.ts +4 -2
  81. package/src/internal/http/client.ts +5 -6
  82. package/src/internal/http/clientError.ts +0 -14
  83. package/src/internal/http/clientResponse.ts +15 -14
  84. package/src/internal/http/multiplex.ts +1 -1
  85. package/src/internal/http/router.ts +1 -1
  86. package/src/internal/http/serverError.ts +0 -20
  87. package/src/internal/http/serverRequest.ts +20 -16
package/src/Http/Body.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  import type * as ParseResult from "@effect/schema/ParseResult"
5
5
  import type * as Schema from "@effect/schema/Schema"
6
6
  import type * as Effect from "effect/Effect"
7
+ import * as Predicate from "effect/Predicate"
7
8
  import type * as Stream_ from "effect/Stream"
8
9
  import type * as PlatformError from "../Error.js"
9
10
  import type * as FileSystem from "../FileSystem.js"
@@ -22,6 +23,12 @@ export const TypeId: unique symbol = internal.TypeId
22
23
  */
23
24
  export type TypeId = typeof TypeId
24
25
 
26
+ /**
27
+ * @since 1.0.0
28
+ * @category refinements
29
+ */
30
+ export const isBody = (u: unknown): u is Body => Predicate.hasProperty(u, TypeId)
31
+
25
32
  /**
26
33
  * @since 1.0.0
27
34
  * @category models
@@ -122,7 +129,13 @@ export interface Raw extends Body.Proto {
122
129
  * @since 1.0.0
123
130
  * @category constructors
124
131
  */
125
- export const raw: (body: unknown) => Raw = internal.raw
132
+ export const raw: (
133
+ body: unknown,
134
+ options?: {
135
+ readonly contentType?: string | undefined
136
+ readonly contentLength?: number | undefined
137
+ } | undefined
138
+ ) => Raw = internal.raw
126
139
 
127
140
  /**
128
141
  * @since 1.0.0
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
+ import * as Error from "@effect/platform/Error"
4
5
  import * as internal from "../internal/http/clientError.js"
5
6
  import type * as ClientRequest from "./ClientRequest.js"
6
7
  import type * as ClientResponse from "./ClientResponse.js"
@@ -23,57 +24,39 @@ export type TypeId = typeof TypeId
23
24
  */
24
25
  export type HttpClientError = RequestError | ResponseError
25
26
 
26
- /**
27
- * @since 1.0.0
28
- */
29
- export declare namespace HttpError {
30
- /**
31
- * @since 1.0.0
32
- * @category models
33
- */
34
- export interface Proto {
35
- readonly [TypeId]: TypeId
36
- readonly _tag: string
37
- }
38
-
39
- /**
40
- * @since 1.0.0
41
- */
42
- export type ProvidedFields = TypeId | "_tag"
43
- }
44
-
45
27
  /**
46
28
  * @since 1.0.0
47
29
  * @category error
48
30
  */
49
- export interface RequestError extends HttpError.Proto {
50
- readonly _tag: "RequestError"
31
+ export class RequestError extends Error.RefailError(TypeId, "RequestError")<{
51
32
  readonly request: ClientRequest.ClientRequest
52
33
  readonly reason: "Transport" | "Encode" | "InvalidUrl"
53
- readonly error: unknown
54
- }
34
+ }> {
35
+ get methodAndUrl() {
36
+ return `${this.request.method} ${this.request.url}`
37
+ }
55
38
 
56
- /**
57
- * @since 1.0.0
58
- * @category error
59
- */
60
- export const RequestError: (props: Omit<RequestError, HttpError.ProvidedFields>) => RequestError = internal.requestError
39
+ get message() {
40
+ const errorString = super.message
41
+ return `${this.reason} error (${this.methodAndUrl}): ${errorString}`
42
+ }
43
+ }
61
44
 
62
45
  /**
63
46
  * @since 1.0.0
64
47
  * @category error
65
48
  */
66
- export interface ResponseError extends HttpError.Proto {
67
- readonly _tag: "ResponseError"
49
+ export class ResponseError extends Error.RefailError(TypeId, "ResponseError")<{
68
50
  readonly request: ClientRequest.ClientRequest
69
51
  readonly response: ClientResponse.ClientResponse
70
52
  readonly reason: "StatusCode" | "Decode" | "EmptyBody"
71
- readonly error: unknown
72
- }
53
+ }> {
54
+ get methodAndUrl() {
55
+ return `${this.request.method} ${this.request.url}`
56
+ }
73
57
 
74
- /**
75
- * @since 1.0.0
76
- * @category error
77
- */
78
- export const ResponseError: (props: Omit<ResponseError, HttpError.ProvidedFields>) => ResponseError =
79
- internal.responseError
58
+ get message() {
59
+ const errorString = super.message
60
+ return `${this.reason} error (${this.response.status} ${this.methodAndUrl}): ${errorString}`
61
+ }
62
+ }
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
- import { dual } from "effect/Function"
4
+ import * as Schema from "@effect/schema/Schema"
5
+ import { dual, identity } from "effect/Function"
5
6
  import type * as Option from "effect/Option"
6
7
  import * as Predicate from "effect/Predicate"
7
8
  import * as ReadonlyArray from "effect/ReadonlyArray"
8
9
  import * as ReadonlyRecord from "effect/ReadonlyRecord"
9
10
  import * as Secret from "effect/Secret"
11
+ import * as String from "effect/String"
10
12
 
11
13
  /**
12
14
  * @since 1.0.0
@@ -20,6 +22,12 @@ export const HeadersTypeId = Symbol.for("@effect/platform/Http/Headers")
20
22
  */
21
23
  export type HeadersTypeId = typeof HeadersTypeId
22
24
 
25
+ /**
26
+ * @since 1.0.0
27
+ * @category refinements
28
+ */
29
+ export const isHeaders = (u: unknown): u is Headers => Predicate.hasProperty(u, HeadersTypeId)
30
+
23
31
  /**
24
32
  * @since 1.0.0
25
33
  * @category models
@@ -29,6 +37,26 @@ export interface Headers {
29
37
  readonly [key: string]: string
30
38
  }
31
39
 
40
+ /**
41
+ * @since 1.0.0
42
+ * @category schemas
43
+ */
44
+ export const schemaFromSelf: Schema.Schema<Headers> = Schema.declare(isHeaders, {
45
+ identifier: "Headers",
46
+ equivalence: () => ReadonlyRecord.getEquivalence(String.Equivalence)
47
+ })
48
+
49
+ /**
50
+ * @since 1.0.0
51
+ * @category schemas
52
+ */
53
+ export const schema: Schema.Schema<Headers, ReadonlyRecord.ReadonlyRecord<string, string>> = Schema.transform(
54
+ Schema.record(Schema.string, Schema.string),
55
+ schemaFromSelf,
56
+ (record) => fromInput(record),
57
+ identity
58
+ )
59
+
32
60
  /**
33
61
  * @since 1.0.0
34
62
  * @category models
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import type * as Cause from "effect/Cause"
5
5
  import type * as FiberId from "effect/FiberId"
6
+ import { RefailError, TypeIdError } from "../Error.js"
6
7
  import * as internal from "../internal/http/serverError.js"
7
8
  import type * as ServerRequest from "./ServerRequest.js"
8
9
  import type * as ServerResponse from "./ServerResponse.js"
@@ -25,34 +26,21 @@ export type TypeId = typeof TypeId
25
26
  */
26
27
  export type HttpServerError = RequestError | ResponseError | RouteNotFound | ServeError
27
28
 
28
- /**
29
- * @since 1.0.0
30
- */
31
- export declare namespace HttpError {
32
- /**
33
- * @since 1.0.0
34
- * @category models
35
- */
36
- export interface Proto {
37
- readonly [TypeId]: TypeId
38
- readonly _tag: string
39
- }
40
-
41
- /**
42
- * @since 1.0.0
43
- */
44
- export type ProvidedFields = TypeId | "_tag"
45
- }
46
-
47
29
  /**
48
30
  * @since 1.0.0
49
31
  * @category error
50
32
  */
51
- export interface RequestError extends HttpError.Proto {
52
- readonly _tag: "RequestError"
33
+ export class RequestError extends RefailError(TypeId, "RequestError")<{
53
34
  readonly request: ServerRequest.ServerRequest
54
35
  readonly reason: "Transport" | "Decode"
55
- readonly error: unknown
36
+ }> {
37
+ get methodAndUrl() {
38
+ return `${this.request.method} ${this.request.url}`
39
+ }
40
+
41
+ get message() {
42
+ return `${this.reason} error (${this.methodAndUrl}): ${super.message}`
43
+ }
56
44
  }
57
45
 
58
46
  /**
@@ -65,57 +53,38 @@ export const isServerError: (u: unknown) => u is HttpServerError = internal.isSe
65
53
  * @since 1.0.0
66
54
  * @category error
67
55
  */
68
- export const RequestError: (props: Omit<RequestError, HttpError.ProvidedFields>) => RequestError = internal.requestError
69
-
70
- /**
71
- * @since 1.0.0
72
- * @category error
73
- */
74
- export interface RouteNotFound extends HttpError.Proto {
75
- readonly _tag: "RouteNotFound"
56
+ export class RouteNotFound extends TypeIdError(TypeId, "RouteNotFound")<{
76
57
  readonly request: ServerRequest.ServerRequest
58
+ }> {
59
+ get message() {
60
+ return `${this.request.method} ${this.request.url} not found`
61
+ }
77
62
  }
78
63
 
79
64
  /**
80
65
  * @since 1.0.0
81
66
  * @category error
82
67
  */
83
- export const RouteNotFound: (props: Omit<RouteNotFound, HttpError.ProvidedFields>) => RouteNotFound =
84
- internal.routeNotFound
85
-
86
- /**
87
- * @since 1.0.0
88
- * @category error
89
- */
90
- export interface ResponseError extends HttpError.Proto {
91
- readonly _tag: "ResponseError"
68
+ export class ResponseError extends RefailError(TypeId, "ResponseError")<{
92
69
  readonly request: ServerRequest.ServerRequest
93
70
  readonly response: ServerResponse.ServerResponse
94
71
  readonly reason: "Decode"
95
- readonly error: unknown
96
- }
97
-
98
- /**
99
- * @since 1.0.0
100
- * @category error
101
- */
102
- export const ResponseError: (props: Omit<ResponseError, HttpError.ProvidedFields>) => ResponseError =
103
- internal.responseError
72
+ }> {
73
+ get methodAndUrl() {
74
+ return `${this.request.method} ${this.request.url}`
75
+ }
104
76
 
105
- /**
106
- * @since 1.0.0
107
- * @category error
108
- */
109
- export interface ServeError extends HttpError.Proto {
110
- readonly _tag: "ServeError"
111
- readonly error: unknown
77
+ get message() {
78
+ return `${this.reason} error (${this.response.status} ${this.methodAndUrl}): ${super.message}`
79
+ }
112
80
  }
113
81
 
114
82
  /**
115
83
  * @since 1.0.0
116
84
  * @category error
117
85
  */
118
- export const ServeError: (props: Omit<ServeError, HttpError.ProvidedFields>) => ServeError = internal.serveError
86
+ export class ServeError extends RefailError(TypeId, "ServeError")<{}> {
87
+ }
119
88
 
120
89
  /**
121
90
  * @since 1.0.0
@@ -31,6 +31,16 @@ export const fromInput = (input: Input): UrlParams => {
31
31
  return ReadonlyArray.fromIterable(Object.entries(input))
32
32
  }
33
33
 
34
+ /**
35
+ * @since 1.0.0
36
+ * @category schemas
37
+ */
38
+ export const schema: Schema.Schema<UrlParams, ReadonlyArray<readonly [string, string]>> = Schema.array(
39
+ Schema.tuple(Schema.string, Schema.string)
40
+ ).pipe(
41
+ Schema.identifier("UrlParams")
42
+ )
43
+
34
44
  /**
35
45
  * @since 1.0.0
36
46
  * @category constructors
@@ -19,7 +19,7 @@ import * as internal from "./internal/platformLogger.js"
19
19
  * import { Effect, Layer, Logger } from "effect"
20
20
  *
21
21
  * const fileLogger = Logger.logfmtLogger.pipe(
22
- * PlatformLogger.toFile("log.txt")
22
+ * PlatformLogger.toFile("/tmp/log.txt")
23
23
  * )
24
24
  * const LoggerLive = Logger.replaceScoped(Logger.defaultLogger, fileLogger).pipe(
25
25
  * Layer.provide(NodeFileSystem.layer)
@@ -48,8 +48,10 @@ class RawImpl implements Body.Raw {
48
48
  }
49
49
 
50
50
  /** @internal */
51
- export const raw = (body: unknown, contentType?: string, contentLength?: number): Body.Raw =>
52
- new RawImpl(body, contentType, contentLength)
51
+ export const raw = (body: unknown, options?: {
52
+ readonly contentType?: string
53
+ readonly contentLength?: number
54
+ }): Body.Raw => new RawImpl(body, options?.contentType, options?.contentLength)
53
55
 
54
56
  class Uint8ArrayImpl implements Body.Uint8Array {
55
57
  readonly [TypeId]: Body.TypeId
@@ -11,13 +11,12 @@ import type * as Scope from "effect/Scope"
11
11
  import * as Stream from "effect/Stream"
12
12
  import type * as Body from "../../Http/Body.js"
13
13
  import type * as Client from "../../Http/Client.js"
14
- import type * as Error from "../../Http/ClientError.js"
14
+ import * as Error from "../../Http/ClientError.js"
15
15
  import type * as ClientRequest from "../../Http/ClientRequest.js"
16
16
  import type * as ClientResponse from "../../Http/ClientResponse.js"
17
17
  import * as Method from "../../Http/Method.js"
18
18
  import * as UrlParams from "../../Http/UrlParams.js"
19
19
  import * as internalBody from "./body.js"
20
- import * as internalError from "./clientError.js"
21
20
  import * as internalRequest from "./clientRequest.js"
22
21
  import * as internalResponse from "./clientResponse.js"
23
22
 
@@ -82,7 +81,7 @@ export const fetch = (options?: RequestInit): Client.Client.Default =>
82
81
  makeDefault((request) =>
83
82
  Effect.flatMap(
84
83
  UrlParams.makeUrl(request.url, request.urlParams, (_) =>
85
- internalError.requestError({
84
+ new Error.RequestError({
86
85
  request,
87
86
  reason: "InvalidUrl",
88
87
  error: _
@@ -109,7 +108,7 @@ export const fetch = (options?: RequestInit): Client.Client.Default =>
109
108
  signal: controller.signal
110
109
  } as any),
111
110
  catch: (_) =>
112
- internalError.requestError({
111
+ new Error.RequestError({
113
112
  request,
114
113
  reason: "Transport",
115
114
  error: _
@@ -419,7 +418,7 @@ export const filterStatus = dual<
419
418
  effect,
420
419
  (response) => f(response.status),
421
420
  (response) =>
422
- internalError.responseError({
421
+ new Error.ResponseError({
423
422
  request,
424
423
  response,
425
424
  reason: "StatusCode",
@@ -571,7 +570,7 @@ export const schemaFunction = dual<
571
570
  Effect.tryMap(encode(a), {
572
571
  try: (body) => new TextEncoder().encode(JSON.stringify(body)),
573
572
  catch: (error) =>
574
- internalError.requestError({
573
+ new Error.RequestError({
575
574
  request,
576
575
  reason: "Encode",
577
576
  error
@@ -1,20 +1,6 @@
1
- import * as Data from "effect/Data"
2
1
  import type * as Error from "../../Http/ClientError.js"
3
2
 
4
3
  /** @internal */
5
4
  export const TypeId: Error.TypeId = Symbol.for(
6
5
  "@effect/platform/Http/Error"
7
6
  ) as Error.TypeId
8
-
9
- const make = <A extends Error.HttpClientError>(tag: A["_tag"]) => (props: Omit<A, Error.HttpError.ProvidedFields>): A =>
10
- Data.struct({
11
- [TypeId]: TypeId,
12
- _tag: tag,
13
- ...props
14
- } as A)
15
-
16
- /** @internal */
17
- export const requestError = make<Error.RequestError>("RequestError")
18
-
19
- /** @internal */
20
- export const responseError = make<Error.ResponseError>("ResponseError")
@@ -3,13 +3,12 @@ import * as Schema from "@effect/schema/Schema"
3
3
  import * as Effect from "effect/Effect"
4
4
  import * as Option from "effect/Option"
5
5
  import * as Stream from "effect/Stream"
6
- import type * as Error from "../../Http/ClientError.js"
6
+ import * as Error from "../../Http/ClientError.js"
7
7
  import type * as ClientRequest from "../../Http/ClientRequest.js"
8
8
  import type * as ClientResponse from "../../Http/ClientResponse.js"
9
9
  import * as Headers from "../../Http/Headers.js"
10
10
  import * as IncomingMessage from "../../Http/IncomingMessage.js"
11
11
  import * as UrlParams from "../../Http/UrlParams.js"
12
- import * as internalError from "./clientError.js"
13
12
 
14
13
  /** @internal */
15
14
  export const TypeId: ClientResponse.TypeId = Symbol.for("@effect/platform/Http/ClientResponse") as ClientResponse.TypeId
@@ -47,25 +46,27 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
47
46
  get stream(): Stream.Stream<Uint8Array, Error.ResponseError> {
48
47
  return this.source.body
49
48
  ? Stream.fromReadableStream(() => this.source.body!, (_) =>
50
- internalError.responseError({
49
+ new Error.ResponseError({
51
50
  request: this.request,
52
51
  response: this,
53
52
  reason: "Decode",
54
53
  error: _
55
54
  }))
56
- : Stream.fail(internalError.responseError({
57
- request: this.request,
58
- response: this,
59
- reason: "EmptyBody",
60
- error: "can not create stream from empty body"
61
- }))
55
+ : Stream.fail(
56
+ new Error.ResponseError({
57
+ request: this.request,
58
+ response: this,
59
+ reason: "EmptyBody",
60
+ error: "can not create stream from empty body"
61
+ })
62
+ )
62
63
  }
63
64
 
64
65
  get json(): Effect.Effect<unknown, Error.ResponseError> {
65
66
  return Effect.tryMap(this.text, {
66
67
  try: (text) => text === "" ? null : JSON.parse(text) as unknown,
67
68
  catch: (_) =>
68
- internalError.responseError({
69
+ new Error.ResponseError({
69
70
  request: this.request,
70
71
  response: this,
71
72
  reason: "Decode",
@@ -79,7 +80,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
79
80
  return this.textBody ??= Effect.tryPromise({
80
81
  try: () => this.source.text(),
81
82
  catch: (_) =>
82
- internalError.responseError({
83
+ new Error.ResponseError({
83
84
  request: this.request,
84
85
  response: this,
85
86
  reason: "Decode",
@@ -93,7 +94,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
93
94
  Effect.try({
94
95
  try: () => UrlParams.fromInput(new URLSearchParams(_)),
95
96
  catch: (_) =>
96
- internalError.responseError({
97
+ new Error.ResponseError({
97
98
  request: this.request,
98
99
  response: this,
99
100
  reason: "Decode",
@@ -107,7 +108,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
107
108
  return this.formDataBody ??= Effect.tryPromise({
108
109
  try: () => this.source.formData(),
109
110
  catch: (_) =>
110
- internalError.responseError({
111
+ new Error.ResponseError({
111
112
  request: this.request,
112
113
  response: this,
113
114
  reason: "Decode",
@@ -121,7 +122,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
121
122
  return this.arrayBufferBody ??= Effect.tryPromise({
122
123
  try: () => this.source.arrayBuffer(),
123
124
  catch: (_) =>
124
- internalError.responseError({
125
+ new Error.ResponseError({
125
126
  request: this.request,
126
127
  response: this,
127
128
  reason: "Decode",
@@ -29,7 +29,7 @@ class MultiplexImpl<R, E>
29
29
  this[TypeId] = TypeId
30
30
 
31
31
  let execute: (request: ServerRequest.ServerRequest) => App.Default<R, E | Error.RouteNotFound> = (request) =>
32
- Effect.fail(Error.RouteNotFound({ request }))
32
+ Effect.fail(new Error.RouteNotFound({ request }))
33
33
 
34
34
  for (let i = apps.length - 1; i >= 0; i--) {
35
35
  const [predicate, app] = apps[i]
@@ -151,7 +151,7 @@ const toHttpApp = <R, E>(
151
151
  result = router.find("GET", request.url)
152
152
  }
153
153
  if (result === undefined) {
154
- return Effect.fail(Error.RouteNotFound({ request }))
154
+ return Effect.fail(new Error.RouteNotFound({ request }))
155
155
  }
156
156
  const route = result.handler
157
157
  if (route.prefix._tag === "Some") {
@@ -1,5 +1,4 @@
1
1
  import * as Cause from "effect/Cause"
2
- import * as Data from "effect/Data"
3
2
  import * as FiberId from "effect/FiberId"
4
3
  import { globalValue } from "effect/GlobalValue"
5
4
  import * as Option from "effect/Option"
@@ -11,28 +10,9 @@ export const TypeId: Error.TypeId = Symbol.for(
11
10
  "@effect/platform/Http/Error"
12
11
  ) as Error.TypeId
13
12
 
14
- const make = <A extends Error.HttpServerError>(tag: A["_tag"]) => (props: Omit<A, Error.HttpError.ProvidedFields>): A =>
15
- Data.struct({
16
- [TypeId]: TypeId,
17
- _tag: tag,
18
- ...props
19
- } as A)
20
-
21
13
  /** @internal */
22
14
  export const isServerError = (u: unknown): u is Error.HttpServerError => Predicate.hasProperty(u, TypeId)
23
15
 
24
- /** @internal */
25
- export const requestError = make<Error.RequestError>("RequestError")
26
-
27
- /** @internal */
28
- export const responseError = make<Error.ResponseError>("ResponseError")
29
-
30
- /** @internal */
31
- export const routeNotFound = make<Error.RouteNotFound>("RouteNotFound")
32
-
33
- /** @internal */
34
- export const serveError = make<Error.ServeError>("ServeError")
35
-
36
16
  /** @internal */
37
17
  export const clientAbortFiberId = globalValue(
38
18
  "@effect/platform/Http/ServerError/clientAbortFiberId",
@@ -98,7 +98,7 @@ export const schemaBodyFormJson = <A, I, R>(schema: Schema.Schema<A, I, R>) => {
98
98
  if (isMultipart(request)) {
99
99
  return Effect.flatMap(
100
100
  Effect.mapError(request.multipart, (error) =>
101
- Error.RequestError({
101
+ new Error.RequestError({
102
102
  request,
103
103
  reason: "Decode",
104
104
  error
@@ -158,16 +158,18 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
158
158
  get stream(): Stream.Stream<Uint8Array, Error.RequestError> {
159
159
  return this.source.body
160
160
  ? Stream.fromReadableStream(() => this.source.body as any, (_) =>
161
- Error.RequestError({
161
+ new Error.RequestError({
162
162
  request: this,
163
163
  reason: "Decode",
164
164
  error: _
165
165
  }))
166
- : Stream.fail(Error.RequestError({
167
- request: this,
168
- reason: "Decode",
169
- error: "can not create stream from empty body"
170
- }))
166
+ : Stream.fail(
167
+ new Error.RequestError({
168
+ request: this,
169
+ reason: "Decode",
170
+ error: "can not create stream from empty body"
171
+ })
172
+ )
171
173
  }
172
174
 
173
175
  private textEffect: Effect.Effect<string, Error.RequestError> | undefined
@@ -179,7 +181,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
179
181
  Effect.tryPromise({
180
182
  try: () => this.source.text(),
181
183
  catch: (error) =>
182
- Error.RequestError({
184
+ new Error.RequestError({
183
185
  request: this,
184
186
  reason: "Decode",
185
187
  error
@@ -193,7 +195,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
193
195
  return Effect.tryMap(this.text, {
194
196
  try: (_) => JSON.parse(_) as unknown,
195
197
  catch: (error) =>
196
- Error.RequestError({
198
+ new Error.RequestError({
197
199
  request: this,
198
200
  reason: "Decode",
199
201
  error
@@ -206,7 +208,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
206
208
  Effect.try({
207
209
  try: () => UrlParams.fromInput(new URLSearchParams(_)),
208
210
  catch: (error) =>
209
- Error.RequestError({
211
+ new Error.RequestError({
210
212
  request: this,
211
213
  reason: "Decode",
212
214
  error
@@ -251,7 +253,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
251
253
  Effect.tryPromise({
252
254
  try: () => this.source.arrayBuffer(),
253
255
  catch: (error) =>
254
- Error.RequestError({
256
+ new Error.RequestError({
255
257
  request: this,
256
258
  reason: "Decode",
257
259
  error
@@ -262,10 +264,12 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
262
264
  }
263
265
 
264
266
  get upgrade(): Effect.Effect<Socket.Socket, Error.RequestError> {
265
- return Effect.fail(Error.RequestError({
266
- request: this,
267
- reason: "Decode",
268
- error: "Not an upgradeable ServerRequest"
269
- }))
267
+ return Effect.fail(
268
+ new Error.RequestError({
269
+ request: this,
270
+ reason: "Decode",
271
+ error: "Not an upgradeable ServerRequest"
272
+ })
273
+ )
270
274
  }
271
275
  }