Skip to content

Commit

Permalink
Merge pull request #38 from badrinathpatchikolla/spark-2.4
Browse files Browse the repository at this point in the history
added the data column in http response case class
  • Loading branch information
badrinathpatchikolla authored May 22, 2023
2 parents 94a2cab + f7c1167 commit 7e60d06
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ final case class Response(
`__STATUS_MSG__`:Option[String] = None,
`__ERROR__`:Option[String] = None,
`__ELAPSED_TIME__`:Long,
`__URL__`:String)
`__URL__`:String,
`__DATA__`: String)

final case class ResponseBatch(
`__ID__`:Seq[String],
Expand Down Expand Up @@ -77,7 +78,7 @@ private[almaren] case class HTTP(
val response = Try(requestHandler(row,session,url,headers,params ++ hiddenParams,method,connectTimeout,readTimeout))
val elapsedTime = System.currentTimeMillis() - startTime
val id = row.getAs[Any](Alias.IdCol).toString

val data = row.getAs[Any](Alias.DataCol).toString
def getResponse(r: requests.Response) = Response(
id,
Some(r.text()),
Expand All @@ -88,15 +89,16 @@ private[almaren] case class HTTP(
case _ => Some(r.statusMessage)
},
`__ELAPSED_TIME__` = elapsedTime,
`__URL__` = url
`__URL__` = url,
`__DATA__` = data
)

response match {
case Success(r) => getResponse(r)
case Failure(re: RequestFailedException) => getResponse(re.response)
case Failure(f) => {
logger.error("Almaren HTTP Request Error", f)
Response(id, `__ERROR__` = Some(f.getMessage), `__ELAPSED_TIME__` = elapsedTime, `__URL__` = url)
Response(id, `__ERROR__` = Some(f.getMessage), `__ELAPSED_TIME__` = elapsedTime, `__URL__` = url, `__DATA__` = data)
}
}
}
Expand Down

0 comments on commit 7e60d06

Please sign in to comment.