-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added cookie helpers #2439
added cookie helpers #2439
Conversation
f23fd0f
to
bcebcbd
Compare
Codecov ReportPatch coverage:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #2439 +/- ##
==========================================
+ Coverage 64.28% 64.76% +0.48%
==========================================
Files 135 135
Lines 7101 7133 +32
Branches 1211 1200 -11
==========================================
+ Hits 4565 4620 +55
+ Misses 2536 2513 -23
☔ View full report in Codecov by Sentry. |
|
69eb79f
to
1de88cb
Compare
1de88cb
to
64e128c
Compare
/** | ||
* Uses the cookie with the given name if it exists and runs `f` afterwards. | ||
*/ | ||
def cookieWith[R, A](name: String)(f: Cookie => ZIO[R, Throwable, A])(implicit trace: Trace): ZIO[R, Throwable, A] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cookieWithZIO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/** | ||
* Returns all cookies from the request. | ||
*/ | ||
def cookies: Option[NonEmptyChunk[Cookie]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def cookies: Option[NonEmptyChunk[Cookie]] = | |
def cookies: Chunk[Cookie] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* Also, you can replace a `NoSuchElementException` from an absent cookie with | ||
* `E`. | ||
*/ | ||
def cookieWithOrFail[R, E, A](name: String)(e: E)(f: Cookie => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def cookieWithOrFail[R, E, A](name: String)(e: E)(f: Cookie => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = | |
def cookieWithOrFail[R, E, A](name: String)(missingCookieError: E)(f: Cookie => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I added all your suggestions! |
private def cookieWithOrFailImpl[R, E, A](name: String)(e: Throwable => E)(f: Cookie => ZIO[R, E, A])(implicit | ||
trace: Trace, | ||
): ZIO[R, E, A] = | ||
ZIO.getOrFailWith(e(new java.util.NoSuchElementException(s"cookie doesn't exist: $name")))(cookie(name)).flatMap(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will create an exception with stacktrace just to be thrown away immediately. This does not seem to be efficient.
I'd change it just simply to
ZIO.getOrFailWith(e(new java.util.NoSuchElementException(s"cookie doesn't exist: $name")))(cookie(name)).flatMap(f) | |
cookie(name) match { | |
case Some(cookie) => f(e) | |
case None => ZIO.fail(e) | |
} |
where e is not a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added your suggestions, thank you!
ae1c681
to
1c8f53b
Compare
If the operators are ok I'll send another PR with updated docs