On Thu, 31 Mar 2005 01:04:04 -0500, Roland Collins <[EMAIL PROTECTED]> wrote:
> But it would be far more flexible (and useful) to trap the LDAP error and
> then re-throw it with your own information appended to it.  This lets the
> developer that uses your API know what is going wrong instead of just
> blindly knowing that it failed.  
>
> ...
>
> This provides far more detail as to what went wrong to the person that has
> to use your API.  I'd say a Boolean return value just won't cut it in this
> case.

I think the boolean value absolutely will cut it, when used in
conjunction with exceptions. If the user is authenicated, return true.
If the user is not authenticated, return false. If something
exceptional happens so that it's not possible to authenticate the user
(e.g. can't connect to the LDAP server), throw an exception.

That way the code that uses authenticate is simple and clear. 

<cfif ldap.authenticate(username, password)>
  <!--- Go on to the home page --->
<cfelse>
  <!--- Back to the login form with "please try again" message. --->
</cfif>

I could choose to handle exceptions thrown by authenticate here (by
surrounding the authenticate() call in a try/catch block). But I don't
have to catch the exception here. I could just let it pass through.
Maybe it will bubble all the way up to my global exception handler
that gives the user a friendly message and sends me an email. [That's
why I'm often the first to know when the LDAP server is down. :-)]

Patrick

-- 
Patrick McElhaney
704.560.9117
http://pmcelhaney.weblogs.us


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]


Reply via email to