Trouble with aligning ParseError and DecodeError
I have an error like this
Which i undersatnd when i read. i can understand the misalignment.
My code is relatively simple.
I just have been fiddiling forever trying to catch tags, but I'm guessing my spec maybe is to blame because i havent really defined an error.
Is there an easy way to just make this type work for now so i can run the code?
Type 'ParseError' is not assignable to type 'HttpApiDecodeError'.
Type 'ParseError' is not assignable to type '{ readonly _tag: "HttpApiDecodeError"; }'.
Types of property '_tag' are incompatible.
Type '"ParseError"' is not assignable to type '"HttpApiDecodeError"'. tsserver (2322) [33, 7]Type 'ParseError' is not assignable to type 'HttpApiDecodeError'.
Type 'ParseError' is not assignable to type '{ readonly _tag: "HttpApiDecodeError"; }'.
Types of property '_tag' are incompatible.
Type '"ParseError"' is not assignable to type '"HttpApiDecodeError"'. tsserver (2322) [33, 7]Which i undersatnd when i read. i can understand the misalignment.
My code is relatively simple.
const decodeNormalizedTreasuryData = Schema.decodeUnknown(
AverageInterestRateTreasuryDataNormalized
);
const makeTreasuryRequest = (client: HttpClient.HttpClient) =>
client
.get(
'https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/avg_interest_rates'
)
.pipe(
Effect.catchTags({
ResponseError: () => Effect.fail(FailedGettingTreasuryData),
RequestError: () => Effect.fail(FailedGettingTreasuryData),
}),
Effect.scoped
);
class FailedGettingTreasuryData {
readonly _tag = 'FailedGettingTreasuryData';
}
const AverageInterestRatesHandler = HttpApiBuilder.group(
TreasuryDataSpec,
'Average Interest Rates on U.S. Treasury Securities',
(handlers) =>
handlers.handle('/avg_interest_rates', () =>
pipe(
HttpClient.HttpClient,
Effect.flatMap(makeTreasuryRequest), // normal api call
Effect.map((clientResponse) => clientResponse.toJSON()),// turn to json
decodeNormalizedTreasuryData // decodes it from unknown to a schema and the schema remaps the keys.
)
)
)const decodeNormalizedTreasuryData = Schema.decodeUnknown(
AverageInterestRateTreasuryDataNormalized
);
const makeTreasuryRequest = (client: HttpClient.HttpClient) =>
client
.get(
'https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/avg_interest_rates'
)
.pipe(
Effect.catchTags({
ResponseError: () => Effect.fail(FailedGettingTreasuryData),
RequestError: () => Effect.fail(FailedGettingTreasuryData),
}),
Effect.scoped
);
class FailedGettingTreasuryData {
readonly _tag = 'FailedGettingTreasuryData';
}
const AverageInterestRatesHandler = HttpApiBuilder.group(
TreasuryDataSpec,
'Average Interest Rates on U.S. Treasury Securities',
(handlers) =>
handlers.handle('/avg_interest_rates', () =>
pipe(
HttpClient.HttpClient,
Effect.flatMap(makeTreasuryRequest), // normal api call
Effect.map((clientResponse) => clientResponse.toJSON()),// turn to json
decodeNormalizedTreasuryData // decodes it from unknown to a schema and the schema remaps the keys.
)
)
)I just have been fiddiling forever trying to catch tags, but I'm guessing my spec maybe is to blame because i havent really defined an error.
Is there an easy way to just make this type work for now so i can run the code?
