>
> Ok, What's the best way to deal with errors thrown when the argument 
> passed doesn't match the argument type declared in the function?
>

I have this small cfc to check if a user's API key exists...  Right now, if 
I don't pass a numeric value for the userID, OpenBD throws an error.  


*CFML Runtime Error**The argument USERID passed to function 
checkExistsAPIKey() is not of type numeric

If an invalid argument is passed, I just want to set my error variable to 
1. 

Should I set the type to 'string' and check the argument another way

<cfif isNumeric(arguments.userID) eq 0>
<cfset error = 1>
</cfif>

Here's the function (which works fine if the argument is numeric)


*
>
> *
> *

*
*
  <cffunction name="checkExistsAPIKey" returntype="struct" output="no" 
access="remote" returnformat="json">
 
  <cfargument name="userID" type="numeric" required="true" default="" 
hint="user email" />
 <cfset checkExistsAPIKeyResults=StructNew()>
<cfset checkExistsAPIKeyResults.error = 0>
<cfset checkExistsAPIKeyResults.success = 0>
 <cfset var local = StructNew()>
<cfset local.userID = "#arguments.userID#">

 <cfquery name="checkExistsAPIKey" datasource="dbAPI" maxRows="1" >

SELECT keyID
FROM tbl_apiKey
WHERE userID = <cfqueryparam value="#local.userID#">

</cfquery>

<cfif checkExistsAPIKey.recordcount eq 0>
<cfset checkExistsAPIKEYResults.error = 1>
<cfelse>
<cfset checkExistsAPIKEYResults.success = 1>
</cfif>
 <cfreturn checkExistsAPIKEYResults> 
  </cffunction>

-- 
online documentation: http://openbd.org/manual/
 http://groups.google.com/group/openbd?hl=en

Reply via email to