Skip to content

Instantly share code, notes, and snippets.

@mattroberts297
Created January 4, 2019 20:19
Show Gist options
  • Save mattroberts297/b89292fd3effcd9c6ce7017e230db209 to your computer and use it in GitHub Desktop.
Save mattroberts297/b89292fd3effcd9c6ce7017e230db209 to your computer and use it in GitHub Desktop.
SignupCore.scala
def signup
[F[_], A: IsParseable[F, ?], B: HasCodes]
(a: A): Signup[B] = {
for {
errorOrCode <- signupImpl(a)
_ <- errorOrCode.fold(
logError,
_ => Success.asRight[LogError] |> Signup.pure
)
} yield {
errorOrCode.left.map(errorToCode[B]).merge
}
}
def logError
(e: SignupError): Signup[LogError Or Success] = e match {
case ParseError =>
log(info("Parse error"))
case CryptoError =>
log(error("Unexpected cryptography error"))
case UnknownDatabaseError =>
log(error("Unexpected database error"))
case DatabaseConflictError =>
log(info("Database conflict"))
case LogError =>
log(error("Unexpected logging error"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment