added error handling

This commit is contained in:
Tony Tam 2013-02-06 17:03:19 -08:00
parent 84e17c7707
commit 852eb0bf49

View File

@ -31,7 +31,8 @@ object ApiExtractor extends RemoteUrl {
implicit val formats = SwaggerSerializers.formats
def fetchApiListings(basePath: String, apis: List[ApiListingReference], apiKey: Option[String] = None): List[ApiListing] = {
for (api <- apis) yield {
(for (api <- apis) yield {
try{
val json = basePath.startsWith("http") match {
case true => {
println("calling: " + ((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json")))
@ -39,8 +40,16 @@ object ApiExtractor extends RemoteUrl {
}
case false => Source.fromFile((basePath + api.path).replaceAll(".\\{format\\}", ".json")).mkString
}
parse(json).extract[ApiListing]
Some(parse(json).extract[ApiListing])
}
catch {
case e:java.io.FileNotFoundException => {
println("WARNING! Unable to read API " + basePath + api.path)
None
}
case _ => None
}
}).flatten.toList
}
def extractApiOperations(basePath: String, references: List[ApiListingReference], apiKey: Option[String] = None) = {