Jump to content

Customizing Exceptions


elabx
 Share

Recommended Posts

Hi! I'm working on a module, and doing some Ajax operations, for example, I am creating some fields and doing this while checking if field already exists:

 if($fieldExists){
    throw new WireException('Field already exists with that name. Please choose another name');
}else{ ... } 

In the response, I'm heading a 200 response code and the following code:

{"error":true,"message":"Field already exists with that name. Please choose another name"}

Is there a way I could customize that error message? 

 if($fieldExists){
    throw new WireException(array("message" => "...", "existingFieldId" => 1));
}else{ ... } 

And expect the response to have the custom info I want? I'm very intrigued on how the exception ends up as a json object in the resopnse. 

Thanks for further answers!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...