Magento Forum

   
can someone take a look at the error handler for indexAction()
 
sjohnson696
Jr. Member
 
Total Posts:  2
Joined:  2012-09-21
 

please let me know what you think.

public function IndexAction() 
    
{
        $fileName 
$this->getRequest()->getParam('file');
        
        
$dir =  Mage::getBaseDir('media').DS'downloads';
        if(!
is_writable($dir))
        
{
        
throw new Exception("downloads is not writabke");    
        
}
        
if ($fileName{
            
try {
                $this
->_processDownload($fileName);
                exit(
0);
            
catch (Mage_Core_Exception $e{
                $this
->_getSession()->addError(Mage::helper('downloadable')->__('not able to process download'));
            
}
        }
        
return $this->_redirectReferer();
        
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

1, the first throw exception is not catched
2, exit should not be used in a web controller
3, you are only caching Mage_Core_Model_Exception but not caching Excetption
4, return is unnecessary in the last line

 
Magento Community Magento Community
Magento Community
Magento Community
 
sjohnson696
Jr. Member
 
Total Posts:  2
Joined:  2012-09-21
 

Hi Thanks for your help, is this what you mean it:

public function IndexAction() 
    
{
        $fileName 
$this->getRequest()->getParam('file');
        
        
$dir =  Mage::getBaseDir('media').DS'downloads';
        if(!
is_writable($dir))
        
{
        
throw new Exception("downloads is not writabke");    
        
}
        
if ($fileName{
            
try {
                $this
->_processDownload($fileName);
            
catch (Mage_Core_Exception $e{
                $this
->_getSession()->addError(Mage::helper('downloadable')->__('not able to process download'));
            
}
                 
catch (Exception $e){
         $this
->_getSession()->addError(Mage::helper('downloadable')->__('Not able to write file.'));
        
}
      
        
    }

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top