export const TodoLive = HttpApiBuilder.group(Api, "todos", (handlers) => {
return handlers
.handle("getTodos", () => {
return pipe(
TodoService.selectAll(),
Effect.timeout("1 second"),
Effect.retry({ times: 3 }),
Effect.catchTag(
"TimeoutException",
() => new HttpApiError.InternalServerError(),
),
);
})
.handle("getTodo", ({ path }) => {
return pipe(
TodoService.selectByTodoId(path.todoId),
Effect.timeout("1 second"),
Effect.retry({ times: 3 }),
Effect.catchTag(
"NoSuchElementException",
() => new HttpApiError.NotFound(),
),
Effect.catchTag(
"TimeoutException",
() => new HttpApiError.InternalServerError(),
),
);
})
.handle("createTodo", ({ payload }) => {
return pipe(
TodoService.create(payload),
Effect.timeout("1 second"),
Effect.retry({ times: 3 }),
Effect.catchTag(
"TimeoutException",
() => new HttpApiError.InternalServerError(),
),
);
});
});
export const TodoLive = HttpApiBuilder.group(Api, "todos", (handlers) => {
return handlers
.handle("getTodos", () => {
return pipe(
TodoService.selectAll(),
Effect.timeout("1 second"),
Effect.retry({ times: 3 }),
Effect.catchTag(
"TimeoutException",
() => new HttpApiError.InternalServerError(),
),
);
})
.handle("getTodo", ({ path }) => {
return pipe(
TodoService.selectByTodoId(path.todoId),
Effect.timeout("1 second"),
Effect.retry({ times: 3 }),
Effect.catchTag(
"NoSuchElementException",
() => new HttpApiError.NotFound(),
),
Effect.catchTag(
"TimeoutException",
() => new HttpApiError.InternalServerError(),
),
);
})
.handle("createTodo", ({ payload }) => {
return pipe(
TodoService.create(payload),
Effect.timeout("1 second"),
Effect.retry({ times: 3 }),
Effect.catchTag(
"TimeoutException",
() => new HttpApiError.InternalServerError(),
),
);
});
});