Skip to content

Commit

Permalink
wip: list-loans print the full text of the website
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsquest committed Oct 2, 2023
1 parent f14abf3 commit 07cb2ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"check:typescript": "tsc"
},
"dependencies": {
"fp-ts": "^2.16.1"
"fp-ts": "^2.16.1",
"undici": "^5.25.3"
}
}
15 changes: 13 additions & 2 deletions src/loans.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { pipe } from "fp-ts/function";
import * as TE from "fp-ts/TaskEither";
import { Dispatcher, request } from "undici";

// type Loans = {
// username: string;
Expand All @@ -8,6 +10,15 @@ import * as TE from "fp-ts/TaskEither";
// }

export const listLoans = (): TE.TaskEither<Error, string> => {
return TE.of("Getting loans");
// return TE.left(new Error("Error getting loans"));
const post = (url: string) =>
TE.tryCatch(
() => request(url),
(reason) => new Error(`Unable to fetch loans: ${String(reason)}`),
);
const parseJson = TE.tryCatchK<Error, [Dispatcher.ResponseData], string>(
(resp) => resp.body.text(),
(reason) => new Error(`Unable to : ${String(reason)}`),
);

return pipe(post("http://www.mediathequederoubaix.fr"), TE.chain(parseJson));
};

0 comments on commit 07cb2ff

Please sign in to comment.