diff --git a/conf/scala/templates/ResourceObject.st b/conf/scala/templates/ResourceObject.st index 2cea5cc4a62..3734100cadc 100644 --- a/conf/scala/templates/ResourceObject.st +++ b/conf/scala/templates/ResourceObject.st @@ -62,8 +62,7 @@ $if(method.hasArguments)$ $endif$ @throws(classOf[APIException]) - def $method.name$($method.argumentDefinitions; separator=", "$) $if(method.hasResponseValue)$:$method.returnValue$$endif$ = { - + def $method.name$($method.argumentDefinitions; separator=", "$)$if(method.hasResponseValue)$: $if(method.returnValueList)$$method.returnValue$$else$Option[$method.returnValue$]$endif$$endif$ = { //parse inputs var resourcePath = "$method.resourcePath$".replace("{format}","json") val method = "$method.methodType$"; @@ -106,11 +105,20 @@ $method.pathParameters:{ argument | $endif$ //make the API Call $if(method.hasResponseValue)$ + var response: String = null + try { $if(method.postObject)$ - val response = apiInvoker.invokeAPI(resourcePath, method, queryParams, postData, headerParams) + response = apiInvoker.invokeAPI(resourcePath, method, queryParams, postData, headerParams) $else$ - val response = apiInvoker.invokeAPI(resourcePath, method, queryParams, null, headerParams) + response = apiInvoker.invokeAPI(resourcePath, method, queryParams, null, headerParams) $endif$ + } catch { + case ex: APIException if ex.getCode == 404 => + $if(method.returnValueList)$ return List() + $else$ return None + $endif$ + case ex: APIException => throw ex + } $else$ $if(method.postObject)$ apiInvoker.invokeAPI(resourcePath, method, queryParams, postData, headerParams) @@ -121,15 +129,22 @@ $endif$ $if(!method.responseVoid)$ $if(method.hasResponseValue)$ - if(null == response || response.length() == 0){ - return null +$if(!method.returnValueList)$ + if(null == response){ + return None } $endif$ +$endif$ $if(!method.returnValueList)$ $if(method.hasResponseValue)$ //create output objects if the response has more than one object val responseObject = APIInvoker.deserialize(response, classOf[$method.returnClassName$]).asInstanceOf[$method.returnValue$] + +$if(method.returnValueList)$ responseObject +$else$ + Some(responseObject) +$endif$ $endif$ $endif$ $if(method.returnValueList)$