-
Notifications
You must be signed in to change notification settings - Fork 5
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
use official ZIO-lambda library in product-move-api #2115
Changes from 1 commit
446f63a
3a6fcb6
4cef536
0a27525
4fd4f86
11758b0
855f231
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ object AwsCredentialsLive { | |
|
||
private val ProfileName = "membership" | ||
|
||
val layer: Layer[String, AwsCredentialsProvider] = | ||
ZLayer.scoped(ZIO.fromAutoCloseable(ZIO.attempt(impl))).mapError(_.toString) | ||
val layer: Layer[Throwable, AwsCredentialsProvider] = | ||
ZLayer.scoped(ZIO.fromAutoCloseable(ZIO.attempt(impl))) | ||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the official zio interpreter expects Throwable as the error, rather than Any, so I had to make everything comply. That is the majority of the changes. |
||
|
||
private def impl: AwsCredentialsProviderChain = | ||
AwsCredentialsProviderChain | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import com.gu.productmove.endpoint.cancel.SubscriptionCancelEndpoint | |
import com.gu.productmove.endpoint.move.{ProductMoveEndpoint, ProductMoveEndpointTypes} | ||
import com.gu.productmove.endpoint.updateamount.UpdateSupporterPlusAmountEndpoint | ||
import com.gu.productmove.framework.ZIOApiGatewayRequestHandler | ||
import com.gu.productmove.framework.ZIOApiGatewayRequestHandler.TIO | ||
import zio.Task | ||
import com.gu.productmove.zuora.rest.{ZuoraClient, ZuoraClientLive, ZuoraGet, ZuoraGetLive} | ||
import com.gu.productmove.zuora.{GetSubscription, GetSubscriptionLive} | ||
import software.amazon.awssdk.auth.credentials.* | ||
|
@@ -65,8 +65,18 @@ object Handler extends ZIOApiGatewayRequestHandler { | |
) | ||
} | ||
|
||
@main | ||
// this will output the HTML to the console | ||
def testDocsHtml(): Unit = { | ||
Handler.runTest( | ||
"GET", | ||
"/docs/", | ||
None, | ||
) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new manual test so I could reproduce the issue locally. |
||
|
||
// this represents all the routes for the server | ||
override val server: List[ServerEndpoint[Any, TIO]] = List( | ||
override val server: List[ServerEndpoint[Any, Task]] = List( | ||
AvailableProductMovesEndpoint.server, | ||
ProductMoveEndpoint.server, | ||
UpdateSupporterPlusAmountEndpoint.server, | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -44,11 +44,11 @@ object SQS { | |||
} | ||||
|
||||
object SQSLive { | ||||
val layer: ZLayer[AwsCredentialsProvider with Stage, ErrorResponse, SQS] = | ||||
val layer: RLayer[AwsCredentialsProvider & Stage, SQS] = | ||||
ZLayer.scoped(for { | ||||
stage <- ZIO.service[Stage] | ||||
sqsClient <- initializeSQSClient().mapError(ex => | ||||
InternalServerError(s"Failed to initialize SQS Client with error: $ex"), | ||||
new Throwable(s"Failed to initialize SQS Client with error", ex), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we were returning InternalServerError but I don't know if it was actually getting used directly, or just converted into an internal server error later anyway There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check? We obvs want to maintain the existing behaviour There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that's a really good point I will check that for sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, existing code we end up with Line 126 in 1b7e0ee
So no matter whether we called it InternalServerError or BadRequest etc, it it would still be an internal server error. If/where we map the error to a ZIO.success then we could use it as a response. |
||||
) | ||||
emailQueueName = EmailQueueName.value | ||||
emailQueueUrlResponse <- getQueue(emailQueueName, sqsClient) | ||||
|
@@ -154,14 +154,14 @@ object SQSLive { | |||
private def getQueue( | ||||
queueName: String, | ||||
sqsAsyncClient: SqsAsyncClient, | ||||
): ZIO[Any, ErrorResponse, GetQueueUrlResponse] = | ||||
): Task[GetQueueUrlResponse] = | ||||
val queueUrl = GetQueueUrlRequest.builder.queueName(queueName).build() | ||||
|
||||
ZIO | ||||
.fromCompletableFuture( | ||||
sqsAsyncClient.getQueueUrl(queueUrl), | ||||
) | ||||
.mapError { ex => InternalServerError(s"Failed to get sqs queue name: $queueName, error: ${ex.getMessage}") } | ||||
.mapError { ex => new Throwable(s"Failed to get sqs queue name: $queueName", ex) } | ||||
|
||||
private def impl(creds: AwsCredentialsProvider): SqsAsyncClient = | ||||
SqsAsyncClient.builder | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import com.gu.productmove.SecretsLive | |
import com.gu.productmove.GuStageLive.Stage | ||
import com.gu.productmove.endpoint.available.AvailableProductMovesEndpointTypes.* | ||
import com.gu.productmove.endpoint.available.Currency.GBP | ||
import com.gu.productmove.framework.ZIOApiGatewayRequestHandler.TIO | ||
import zio.Task | ||
import com.gu.productmove.framework.{LambdaEndpoint, ZIOApiGatewayRequestHandler} | ||
import com.gu.productmove.zuora.GetAccount.{GetAccountResponse, PaymentMethodResponse} | ||
import com.gu.productmove.zuora.* | ||
|
@@ -40,7 +40,7 @@ object AvailableProductMovesEndpoint { | |
Unit, | ||
OutputBody, | ||
Any, | ||
ZIOApiGatewayRequestHandler.TIO, | ||
Task, | ||
] = { | ||
val subscriptionNameCapture: EndpointInput.PathCapture[String] = | ||
EndpointInput.PathCapture[String]( | ||
|
@@ -74,13 +74,13 @@ object AvailableProductMovesEndpoint { | |
.description("""Returns an array of eligible products that the given subscription could be moved to, | ||
|which will be empty if there aren't any for the given subscription. | ||
|""".stripMargin) | ||
.serverLogic[TIO] { subscriptionName => | ||
.serverLogic[Task] { subscriptionName => | ||
run(subscriptionName).tapEither(result => ZIO.log("result tapped: " + result)).map(Right.apply) | ||
} | ||
} | ||
|
||
// sub to test on: "A-S00334930" | ||
private def run(subscriptionName: String): TIO[OutputBody] = | ||
private def run(subscriptionName: String): Task[OutputBody] = | ||
runWithEnvironment(SubscriptionName("A-S00334930")).provide( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this shouldn't have been hard coded, it should have used the one passed from the client! |
||
AwsS3Live.layer, | ||
AwsCredentialsLive.layer, | ||
|
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 is the new library added in softwaremill/tapir#2975