diff --git a/server/src/main/scala/za/co/absa/atum/server/model/ErrorResponse.scala b/server/src/main/scala/za/co/absa/atum/server/model/ErrorResponse.scala index 4869f4208..3ce5aabe4 100644 --- a/server/src/main/scala/za/co/absa/atum/server/model/ErrorResponse.scala +++ b/server/src/main/scala/za/co/absa/atum/server/model/ErrorResponse.scala @@ -18,28 +18,35 @@ package za.co.absa.atum.server.model import play.api.libs.json.{Json, Reads, Writes} +import java.util.UUID + object ErrorResponse { - sealed trait ErrorResponse { + sealed trait ErrorResponse extends ResponseEnvelope { def message: String } implicit val reads: Reads[ErrorResponse] = Json.reads[ErrorResponse] implicit val writes: Writes[ErrorResponse] = Json.writes[ErrorResponse] - final case class BadRequestResponse(message: String) extends ErrorResponse + final case class BadRequestResponse(message: String, override val requestId: UUID = UUID.randomUUID()) + extends ErrorResponse implicit val readsBadRequestResponse: Reads[BadRequestResponse] = Json.reads[BadRequestResponse] implicit val writesBadRequestResponse: Writes[BadRequestResponse] = Json.writes[BadRequestResponse] - final case class GeneralErrorResponse(message: String) extends ErrorResponse + final case class GeneralErrorResponse(message: String, override val requestId: UUID = UUID.randomUUID()) + extends ErrorResponse implicit val readsGeneralErrorResponse: Reads[GeneralErrorResponse] = Json.reads[GeneralErrorResponse] implicit val writesGeneralErrorResponse: Writes[GeneralErrorResponse] = Json.writes[GeneralErrorResponse] - final case class InternalServerErrorResponse(message: String) extends ErrorResponse + final case class InternalServerErrorResponse(message: String, override val requestId: UUID = UUID.randomUUID()) + extends ErrorResponse - implicit val readsInternalServerErrorResponse: Reads[InternalServerErrorResponse] = Json.reads[InternalServerErrorResponse] - implicit val writesInternalServerErrorResponse: Writes[InternalServerErrorResponse] = Json.writes[InternalServerErrorResponse] + implicit val readsInternalServerErrorResponse: Reads[InternalServerErrorResponse] = + Json.reads[InternalServerErrorResponse] + implicit val writesInternalServerErrorResponse: Writes[InternalServerErrorResponse] = + Json.writes[InternalServerErrorResponse] } diff --git a/server/src/main/scala/za/co/absa/atum/server/model/ResponseEnvelope.scala b/server/src/main/scala/za/co/absa/atum/server/model/ResponseEnvelope.scala new file mode 100644 index 000000000..8fb991d7c --- /dev/null +++ b/server/src/main/scala/za/co/absa/atum/server/model/ResponseEnvelope.scala @@ -0,0 +1,23 @@ +/* + * Copyright 2021 ABSA Group Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package za.co.absa.atum.server.model + +import java.util.UUID + +trait ResponseEnvelope { + def requestId: UUID +} diff --git a/server/src/main/scala/za/co/absa/atum/server/model/SuccessResponse.scala b/server/src/main/scala/za/co/absa/atum/server/model/SuccessResponse.scala index 90440a0bb..5320a22f8 100644 --- a/server/src/main/scala/za/co/absa/atum/server/model/SuccessResponse.scala +++ b/server/src/main/scala/za/co/absa/atum/server/model/SuccessResponse.scala @@ -16,11 +16,16 @@ package za.co.absa.atum.server.model +import java.util.UUID + object SuccessResponse { - sealed trait SuccessResponse + sealed trait SuccessResponse extends ResponseEnvelope + + case class SingleSuccessResponse[T](data: T, override val requestId: UUID = UUID.randomUUID()) + extends SuccessResponse - case class SingleSuccessResponse[T](data: T) extends SuccessResponse - case class MultiSuccessResponse[T](data: Seq[T]) extends SuccessResponse + case class MultiSuccessResponse[T](data: Seq[T], override val requestId: UUID = UUID.randomUUID()) + extends SuccessResponse }