I have created Magento Custom V2 API it's working fine, but the fault code is returning wrong.

My Code is


<?xml version="1.0"?>
            <test_customer translate="title" module="test">
                <title>Custom Customer API</title>
                    <multiCreate translate="title" module="test">
                        <title>Multiple customer creation</title>
                <faults module="test">
                        <message>Invalid customer data. </message>
                        <message>Invalid filters specified. </message>
                        <message>Customer not exists.</message>
                        <message>Customer not deleted. </message>
                        <message>No/Invalid Data was found. </message>
                        <message>Input should be an Array. </message>
                        <message>Customer sub group not exists.</message>
                        <message> Invalid additional attributes data. </message>
                        <message>Customer Exists.</message>
                        <message>API Limit is exceeded.</message>



               <test translate="title" module="test">
                   <customer translate="title" module="test">
                       <multiCreate translate="title" module="test">




class Hello_Test_Model_Customer_Api_V2 extends Hello_Test_Model_Customer_Api{

    public function multiCreate($customerData){


           $email = $customerData->email;
           $customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('email');

            foreach($customers as $customers_Data){
                $customer_email = $customers_Data->getEmail();
                if($customer_email == $email){
                    $this->_fault('customer_exist','Customer is Exists.');

       }catch (Exception $ex){

        return $customer->getId();



here i'm validating customer by E-Mail & throwing exception correct but it's not returing original fault message?

result is

SoapFault exception: [C100] customer_exist

Actual Error Code is C108 & Message is Customer is exists

Please suggest me if i went wrong?

1 Answer 1


$this->_fault() throws a Mage_Api_Exception exception. Because this is within your try..catch block, you catch this Mage_Api_Exception with catch (Exception $ex) where you throw a different Mage_Api_Exception with the same message but the data_invalid key.

What you want to do instead is only catch exceptions which are not of the Mage_Api_Exception type. I would suggest catching and rethrowing Mage_Api_Exception like this, and use your current catch block for all other exceptions:

   } catch (Mage_Api_Exception $ex) {
       throw $ex;
   } catch (Exception $ex) {
       $this->_fault('data_invalid', $ex->getMessage());
  • $this->_fault('customer_exist','Customer Exists.'); second param is Custom message right? why it's not returning?
    – M_N
    Aug 21, 2015 at 9:22
  • Yes, the message is used from the second parameter if given, otherwise from the definition in api.xml. Look at the raw SOAP response and check for <faultstring> Aug 21, 2015 at 9:27
  • Btw, I updated my answer, the actual exception type in the API model is Mage_Api_Exception, it gets converted to SoapFault later in the API handler Aug 21, 2015 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.