How To Get A User Friendly Error Instead Of A Raw Code Exception "the Right Way"

Hi,

i have a model method upload file, and when the method crashes it throws an exception. What happens is that i end up getting this:

What can i do to just display a user friendly error message the "right way" istead of this coding exception thing?

my model:




public function uploadFile(){

		

		$uploadedFile = CUploadedFile::getInstance($this,'path_to_file');


		if(!empty($uploadedFile)){


			try{

				$uploadedFile->saveAs(Constantes::path_to_file.$uploadedFile->name,FALSE);

				$this->path_to_file = Constantes::path_to_file.$uploadedFile->name;


				//save Thumb

				$image = new EasyImage(Constantes::path_to_file.$uploadedFile->name);

				$image->resize(100, 100);

				$image->save(Constantes::path_to_file.'thumbs/'.'thumb_'.$uploadedFile->name);

			}catch(Exception $e){

				throw new Exception("Erro ao fazer upload da imagem");

			}


		}


	}




the controller snippet of the called method:




if(isset($_POST['ComentarioDeComentario'])){

			

			$model = new ComentarioDeComentario();

			

			$model->uploadFile();

			$model->conteudo = strip_tags($_POST['ComentarioDeComentario']['conteudo']);

			$model->comentario_id = $_POST['ComentarioDeComentario']['comentario_id'];

			$model->user_id = Yii::app()->user->getState('id');


			if($model->save()){

				$this->refresh();

			} 


		}




thks!

Hi

I think you deleted error action from your siteController.

You need to create error action first

Then change config/main.php




'errorHandler'=>array(

    // use 'site/error' action to display errors

    'errorAction'=>'home/error',

),



hope this helps!!!

Just set debug to false :)

… and, of course, write all error messages in Norwegian…

Norwegian errors will end up not being so friendly after all, kkk.

The debug false worked fine! I forgot about that, thks!

You are right, of course.

More seriously, I guess you already know, but I thought I’d mention that you can customize the error page located in views\site\error.php

I have seen some great examples of helpful error pages.