Skip to content

Commit

Permalink
use cause for DiscordRESTError
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Aug 8, 2024
1 parent 008474f commit 8f7ea87
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/DiscordREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class DiscordRESTError extends TypeIdError(
DiscordRESTErrorTypeId,
"DiscordRESTError",
)<{
error: HttpError.HttpClientError
cause: HttpError.HttpClientError
body?: unknown
}> {
get message() {
const httpMessage = this.error.message
const httpMessage = this.cause.message
return this.body !== undefined
? `${httpMessage}: ${JSON.stringify(this.body)}`
: httpMessage
Expand Down Expand Up @@ -158,15 +158,15 @@ const make = Effect.gen(function* () {
}),
),
),
HttpClient.catchAll(error =>
error.reason === "StatusCode"
? error.response.json.pipe(
Effect.mapError(_ => new DiscordRESTError({ error })),
HttpClient.catchAll(cause =>
cause.reason === "StatusCode"
? cause.response.json.pipe(
Effect.mapError(_ => new DiscordRESTError({ cause })),
Effect.flatMap(body =>
Effect.fail(new DiscordRESTError({ error, body })),
Effect.fail(new DiscordRESTError({ cause, body })),
),
)
: Effect.fail(new DiscordRESTError({ error })),
: Effect.fail(new DiscordRESTError({ cause })),
),
)

Expand All @@ -184,11 +184,11 @@ const make = Effect.gen(function* () {
),
Effect.tap(response => updateBuckets(request, response)),
Effect.catchTag("DiscordRESTError", e => {
if (e.error.reason !== "StatusCode") {
if (e.cause.reason !== "StatusCode") {
return Effect.fail(e)
}

const response = e.error.response
const response = e.cause.response

switch (response.status) {
case 403:
Expand Down

0 comments on commit 8f7ea87

Please sign in to comment.