Skip to content

Commit

Permalink
Merge pull request #2251 from constantine2nd/develop
Browse files Browse the repository at this point in the history
Write Metric regarding request timeout
  • Loading branch information
simonredfern committed Aug 24, 2023
2 parents 5cff441 + 6e6ed99 commit cded099
Show file tree
Hide file tree
Showing 7 changed files with 463 additions and 415 deletions.
1 change: 1 addition & 0 deletions obp-api/src/main/scala/code/api/util/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
* - We cannot assign the role to non existing bank
*/
cc: CallContext => {
implicit val ec = EndpointContext(Some(cc)) // Supply call context in case of saving row to the metric table
// if authentication check, do authorizedAccess, else do Rate Limit check
for {
(boxUser, callContext) <- checkAuth(cc)
Expand Down
11 changes: 11 additions & 0 deletions obp-api/src/main/scala/code/api/util/ErrorMessages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package code.api.util
import java.util.Objects
import java.util.regex.Pattern

import code.api.APIFailureNewStyle
import com.openbankproject.commons.model.enums.TransactionRequestStatus._
import code.api.Constant._
import code.api.util.ApiRole.{CanCreateAnyTransactionRequest, canCreateEntitlementAtAnyBank, canCreateEntitlementAtOneBank}
import code.views.system.ViewDefinition
import net.liftweb.json.{Extraction, JsonAST}
import net.liftweb.util.StringHelpers

object ErrorMessages {
Expand All @@ -20,6 +22,15 @@ object ErrorMessages {
// 6) Any messaage defined here should be considered "fair game" to return over the API. Thus:
// 7) Since the existance of "OBP-..." in a message is used to determine if we should display to a user if display_internal_errors=false, do *not* concatenate internal or core banking system error messages to these strings.


def apiFailureToString(code: Int, message: String, context: Option[CallContext]): String = JsonAST.compactRender(
Extraction.decompose(
APIFailureNewStyle(failMsg = message, failCode = code, context.map(_.toLight))
)
)
def apiFailureToString(code: Int, message: String, context: CallContext): String =
apiFailureToString(code, message, Some(context))

// Infrastructure / config level messages (OBP-00XXX)
val HostnameNotSpecified = "OBP-00001: Hostname not specified. Could not get hostname from Props. Please edit your props file. Here are some example settings: hostname=http://127.0.0.1:8080 or hostname=https://www.example.com"
val DataImportDisabled = "OBP-00002: Data import is disabled for this API instance."
Expand Down
6 changes: 1 addition & 5 deletions obp-api/src/main/scala/code/api/util/FutureUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ object FutureUtil {
val timerTask = new TimerTask() {
def run() : Unit = {
p.tryFailure {
val error: String = JsonAST.compactRender(
Extraction.decompose(
APIFailureNewStyle(failMsg = ErrorMessages.requestTimeout, failCode = 408, cc.context.map(_.toLight))
)
)
val error: String = ErrorMessages.apiFailureToString(408, ErrorMessages.requestTimeout, cc.context)
new TimeoutException(error)
}
}
Expand Down
Loading

0 comments on commit cded099

Please sign in to comment.