Skip to content
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

CORE-81: strip info from error messages before responding #3213

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait HttpClientUtils extends LazyLogging {
executeRequest(http, httpRequest) recover { case t: Throwable =>
throw new RawlsExceptionWithErrorReport(
ErrorReport(StatusCodes.InternalServerError,
s"HTTP call failed: ${httpRequest.uri}. Response: ${t.getMessage}",
s"HTTP call failed: ${filterPrivate(httpRequest.uri)}. Response: ${t.getMessage}",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It felt helpful to include the target uri in the error message, as long as that uri was not private; so I added a filter instead of removing the uri altogether

t
)
)
Expand All @@ -44,15 +44,15 @@ trait HttpClientUtils extends LazyLogging {
} else {
Unmarshal(response.entity).to[String] map { entityAsString =>
logger.debug(
s"HTTP error status ${response.status} calling URI ${httpRequest.uri}. Response: $entityAsString"
s"HTTP error status ${response.status} calling URI ${filterPrivate(httpRequest.uri)}. Response: $entityAsString"
)
val message =
if (response.status == StatusCodes.Unauthorized)
s"The service indicated that this call was unauthorized. " +
s"If you believe this is a mistake, please try your request again. " +
s"Error occurred calling uri ${httpRequest.uri}"
s"Error occurred calling uri ${filterPrivate(httpRequest.uri)}"
else
s"HTTP error calling URI ${httpRequest.uri}. Response: ${entityAsString.take(1000)}"
s"HTTP error calling URI ${filterPrivate(httpRequest.uri)}. Response: ${entityAsString.take(1000)}"
throw new RawlsExceptionWithErrorReport(ErrorReport(response.status, message))
}
}
Expand All @@ -64,7 +64,7 @@ trait HttpClientUtils extends LazyLogging {
executeRequest(http, httpRequest) recover { case t: Throwable =>
throw new RawlsExceptionWithErrorReport(
ErrorReport(StatusCodes.InternalServerError,
s"HTTP call failed: ${httpRequest.uri}. Response: ${t.getMessage}",
s"HTTP call failed: ${filterPrivate(httpRequest.uri)}. Response: ${t.getMessage}",
t
)
)
Expand All @@ -80,16 +80,22 @@ trait HttpClientUtils extends LazyLogging {
} else {
Unmarshal(response.entity).to[String] map { entityAsString =>
logger.debug(
s"HTTP error status ${response.status} calling URI ${httpRequest.uri}. Response: $entityAsString"
s"HTTP error status ${response.status} calling URI ${filterPrivate(httpRequest.uri)}. Response: $entityAsString"
)
throw new RawlsExceptionWithErrorReport(
ErrorReport(response.status,
s"HTTP error calling URI ${httpRequest.uri}. Response: ${entityAsString.take(1000)}"
ErrorReport(
response.status,
s"HTTP error calling URI ${filterPrivate(httpRequest.uri)}. Response: ${entityAsString.take(1000)}"
)
)
}
}
}

// don't display private Uris to end users
private def filterPrivate(uri: Uri): String =
if (uri.authority.toString().contains("-priv")) "" else uri.toString()

}

case class HttpClientUtilsStandard()(implicit val materializer: Materializer, val executionContext: ExecutionContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ object RawlsApiService extends LazyLogging {
complete(
withErrorReport.errorReport.statusCode.getOrElse(
StatusCodes.InternalServerError
) -> withErrorReport.errorReport
) -> withErrorReport.errorReport.copy(stackTrace = Seq())
)
case rollback: SQLTransactionRollbackException =>
logger.error(
s"ROLLBACK EXCEPTION, PROBABLE DEADLOCK: ${rollback.getMessage} [${rollback.getErrorCode} ${rollback.getSQLState}] ${rollback.getNextException}",
rollback
)
Sentry.captureException(rollback)
complete(StatusCodes.InternalServerError -> ErrorReport(rollback))
complete(StatusCodes.InternalServerError -> ErrorReport(rollback).copy(stackTrace = Seq()))
case sql: SQLException =>
val sentryId = Sentry.captureException(sql)
logger.error(
Expand All @@ -90,7 +90,7 @@ object RawlsApiService extends LazyLogging {
logger.error(e.getMessage)
}
Sentry.captureException(e)
complete(StatusCodes.InternalServerError -> ErrorReport(e))
complete(StatusCodes.InternalServerError -> ErrorReport(e).copy(stackTrace = Seq()))
}
}

Expand Down