From 852eb0bf490aa32e7d99618aac0a44d51004cde0 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 6 Feb 2013 17:03:19 -0800 Subject: [PATCH] added error handling --- .../swagger/codegen/util/ApiExtractor.scala | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/scala/com/wordnik/swagger/codegen/util/ApiExtractor.scala b/src/main/scala/com/wordnik/swagger/codegen/util/ApiExtractor.scala index 78b7ef002cb..4c37e06e3c6 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/util/ApiExtractor.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/util/ApiExtractor.scala @@ -31,16 +31,25 @@ 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 { - val json = basePath.startsWith("http") match { - case true => { - println("calling: " + ((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json"))) - urlToString((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json")) - } - case false => Source.fromFile((basePath + api.path).replaceAll(".\\{format\\}", ".json")).mkString - } - parse(json).extract[ApiListing] - } + (for (api <- apis) yield { + try{ + val json = basePath.startsWith("http") match { + case true => { + println("calling: " + ((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json"))) + urlToString((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json")) + } + case false => Source.fromFile((basePath + api.path).replaceAll(".\\{format\\}", ".json")).mkString + } + 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) = {