Skip to content

Commit

Permalink
Merge pull request #78 from augustjune/fixing
Browse files Browse the repository at this point in the history
Fixing stuff before the release
  • Loading branch information
augustjune authored Nov 11, 2019
2 parents 41abb17 + 80ed6eb commit 44a6cbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions core/js/src/main/scala/canoe/api/clients/AjaxClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ private[api] class AjaxClient[F[_]: Async: ContextShift](token: String) extends
*/
def execute[Req, Res](request: Req)(implicit M: Method[Req, Res]): F[Res] = {
implicit val responseDecoder: Decoder[Response[Res]] = Response.decoder[Res](M.decoder)
console.log(s"Executing ${M.name}")

sendJsonRequest(request, M).map(decode[Response[Res]]).flatMap {
case Left(error) => ResponseDecodingError(error.toString).raiseError[F, Res]
case Left(error) => handleUnknownEntity(M.name, request, error.getMessage)
case Right(response) => handleTelegramResponse(M, request)(response)
}
}

private def handleUnknownEntity[I, A](method: String, input: I, error: String): F[A] = {
console.error(
s"Received unknown Telegram entity during execution of '$method' method. \nInput data: $input. \n${error}"
)
ResponseDecodingError(error.toString).raiseError[F, A]
}

private def handleTelegramResponse[A, I, C](m: Method[I, A], input: I)(response: Response[A]): F[A] =
response match {
case Response(true, Some(result), _, _, _) => result.pure[F]
Expand Down
4 changes: 3 additions & 1 deletion core/shared/src/main/scala/canoe/api/sources/Polling.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package canoe.api.sources

import canoe.api.{ResponseDecodingError, UpdateSource}
import canoe.api.{ResponseDecodingError, UpdateSource, TelegramClient}
import canoe.methods.updates.GetUpdates
import canoe.models.Update
import canoe.syntax.methodOps
import cats.ApplicativeError
import cats.effect.Timer
import cats.syntax.functor.toFunctorOps
import cats.syntax.applicativeError.catsSyntaxApplicativeError
import fs2.Stream
import io.circe.parser.decode

Expand Down

0 comments on commit 44a6cbf

Please sign in to comment.