wip
This commit is contained in:
parent
095ac520a9
commit
f04f6aa147
1 changed files with 18 additions and 1 deletions
|
|
@ -30,6 +30,20 @@ class APIResponseError extends Schema.TaggedErrorClass<APIResponseError>()("APIR
|
||||||
|
|
||||||
type APIError = APIRequestError | APIResponseError;
|
type APIError = APIRequestError | APIResponseError;
|
||||||
|
|
||||||
|
class WooCommerceErrorBody extends Schema.Class<WooCommerceErrorBody>("WooCommerceErrorBody")({
|
||||||
|
code: Schema.String,
|
||||||
|
data: Schema.Struct({
|
||||||
|
status: Schema.Int,
|
||||||
|
}),
|
||||||
|
message: Schema.String,
|
||||||
|
}) {}
|
||||||
|
class WooCommerceError extends Schema.Class<WooCommerceError>("WooCommerceError")({
|
||||||
|
body: WooCommerceErrorBody,
|
||||||
|
status: Schema.Number,
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
type APIResponse<T> = T | WooCommerceError;
|
||||||
|
|
||||||
/** Client `fetch` contenant les options et en-têtes de Requêtes pré-renseignées. */
|
/** Client `fetch` contenant les options et en-têtes de Requêtes pré-renseignées. */
|
||||||
const APIFetchClient = FetchHttpClient.layer.pipe(
|
const APIFetchClient = FetchHttpClient.layer.pipe(
|
||||||
Layer.provide(
|
Layer.provide(
|
||||||
|
|
@ -96,7 +110,7 @@ class APIClient extends Context.Service<APIClient>()("haikuatelier.fr/APIClient"
|
||||||
});
|
});
|
||||||
|
|
||||||
const AddProductToCart = Effect.fn("AppClient.AddProductToCart")(
|
const AddProductToCart = Effect.fn("AppClient.AddProductToCart")(
|
||||||
function*(nonce: string, productToAdd: CartProduct): Effect.fn.Return<WooCommerceCart, APIError> {
|
function*(nonce: string, productToAdd: CartProduct): Effect.fn.Return<APIResponse<WooCommerceCart>, APIError> {
|
||||||
const request = pipe(
|
const request = pipe(
|
||||||
HttpClientRequest.post(`/wp-json/wc/store/cart/add-item`),
|
HttpClientRequest.post(`/wp-json/wc/store/cart/add-item`),
|
||||||
HttpClientRequest.setHeader("Nonce", nonce),
|
HttpClientRequest.setHeader("Nonce", nonce),
|
||||||
|
|
@ -109,6 +123,9 @@ class APIClient extends Context.Service<APIClient>()("haikuatelier.fr/APIClient"
|
||||||
Effect.flatMap(HttpClientResponse.schemaBodyJson(WooCommerceCart)),
|
Effect.flatMap(HttpClientResponse.schemaBodyJson(WooCommerceCart)),
|
||||||
Effect.mapError(error => matchAPIError(error)),
|
Effect.mapError(error => matchAPIError(error)),
|
||||||
Effect.tapError(error => printErrorAsSuccinctMessage(error)),
|
Effect.tapError(error => printErrorAsSuccinctMessage(error)),
|
||||||
|
Effect.catchTag("APIResponseError", error => {
|
||||||
|
if (error.cause.)
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue