-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Krzysztof Palcowski
committed
Mar 1, 2024
1 parent
f9f94a0
commit 97f4f15
Showing
5 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
core/src/main/scala/pl/iterators/baklava/core/model/RouteErrorResponse.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package pl.iterators.baklava.core.model | ||
|
||
final case class RouteErrorResponse[T](result: T, status: Int) { | ||
lazy val jsonData: RouteErrorResponseJsonData = | ||
RouteErrorResponseJsonData(s"result:${RouteErrorResponse.typeFromResult(result)}", status) | ||
|
||
def resultName: String = result.getClass.getSimpleName.replaceAll("$", "") | ||
} | ||
final case class RouteErrorResponseJsonData(`type`: String, status: Int) | ||
|
||
object RouteErrorResponse { | ||
def typeFromResult[T](result: T): String = { | ||
val cls = result.getClass | ||
val leading = | ||
Option(cls.getEnclosingClass) | ||
.map(_.getSimpleName.filterNot(_ == '$').replace("Result", "").replaceAll("([a-z])([A-Z])", "$1-$2").toLowerCase + ":") | ||
leading.getOrElse("") + | ||
cls.getSimpleName.filterNot(_ == '$').replaceAll("([a-z])([A-Z])", "$1-$2").toLowerCase // kebabify | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters