Skip to content

How to lift a pure value into the effect-space inside an async function #1336

Answered by harrhp
dirkil asked this question in Q&A
Discussion options

You must be logged in to vote

Prelude.Aff can't return non-exceptional errors, you should use Prelude.AffMaybe for that. It expects Fin<A> as return value, but Prelude.FailAff returns Aff<A>, so you have to use Prelude.FinFail instead

Aff<Guid> CreateOffer(Guid mandantId, string offerJson)
{
  return AffMaybe(async () =>
  {
    var content = new StringContent(immobilieJson, Encoding.UTF8, "application/json");
    var response = await _httpClient.PostAsync($"api/offers/{mandantId}", content);
    if (response.StatusCode == HttpStatusCode.OK)
    {
      return await response.Content.ReadFromJsonAsync<Guid>();
    }
    var errorContent = await response.Content.ReadAsStringAsync();
    var error = Error.New((int)respon…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dirkil
Comment options

Answer selected by dirkil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants