The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error Handling with WHM when create account

Discussion in 'General Discussion' started by lhoezee, Dec 22, 2008.

  1. lhoezee

    lhoezee Member

    Joined:
    Dec 22, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hello everyone!

    I have a question about this integration: http://cpanel.net/remoteaccess-php.html

    When I run the "createacct" function everything works out fine however, if a domain already exists on my server I get the following error:

    Sorry, a DNS entry for domain.com already exists, please delete it first (from all servers in the dns cluster)

    That's not the best error message to display to clients... I tried doing something like this but it didn't work, any suggestions?

    PHP:
    if ($test->errors[0] == "Sorry, a DNS entry for $domain already exists, please delete it first (from all servers in the dns cluster)") {
        
    $test->errors[0] = "something else";
        print 
    $test->errors[0];
    }
    When I print $test->errors[0] and "Sorry, a DNS entry for $domain already exists, please delete it first (from all servers in the dns cluster)" they are the same but it doesn't actually get inside.

    Here is how the messages are handled now in the class:

    PHP:
    if($xml->result->status==1)
    {
         
    $result['status']=$xml->result->status;
         
    $result['statusmsg']=$xml->result->statusmsg;
         
    $result['ip']=$xml->result->options->ip;
         
    $result['nameserver']=$xml->result->options->nameserver;
         
    $result['nameserver2']=$xml->result->options->nameserver2;
         
    $result['nameserver3']=$xml->result->options->nameserver3;
         
    $result['nameserver4']=$xml->result->options->nameserver4;
         
    $result['package']=$xml->result->options->package;
         
    $result['rawout']=$xml->result->rawout;
         return 
    $result;
    }
    else
    {
         
    $this->errors[]=$xml->result->statusmsg;
         return 
    false;
    }
    It would be nice if there was something like this:
    PHP:
    $this->errors[]=$xml->result->statuscode;
    statuscode would contain a numeric value so I can do a switch statement on that value to display what I would like to display.

    I hope that helps.

    Let me know if you need more info from me.

    Thanks,

    Luke
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Are you trimming the newline that occurs both before and after that phrase in the raw XML output? If not, that would explain why your exact comparison (==) is not working as you intend.
     
  3. lhoezee

    lhoezee Member

    Joined:
    Dec 22, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Wow!! I can't be believe I didn't think of that... it works!

    Thanks a lot. Any thoughts on the error handling statuscode? Unnecessary or good idea?
     
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Statuscode tends to be the return value from the Perl scripts these APIs eventually call. In Perl, a return value of 1 indicates success, 0 is typically used to indicate non-success. Therefore, the statuscode will usually be either 1 or 0, 1 indicating success.

    If I was coding an application that used the APIs, I'd be looking at the statuscode solely to determine if my function call was successful. If it wasn't 1 (1 indicating success), then I'd go into my error handling routines.
     
    #4 cPanelDavidG, Dec 22, 2008
    Last edited: Dec 22, 2008
  5. lhoezee

    lhoezee Member

    Joined:
    Dec 22, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for the time. That helps a lot.

    Have a good week!

    Luke
     
Loading...

Share This Page