Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:54:56+00:00 2026-06-13T12:54:56+00:00

function put($id, $name) { try { product::put($id, $name); } catch(\util\BadNameException $e) { throw new

  • 0
function put($id, $name)
{
   try
   {
       product::put($id, $name);
   }
   catch(\util\BadNameException $e)
   {
       throw new RestException(400, "Please supply a better name.");
   }
}

When returning the error message I also want to include the result of (array)product::getNamingConvention() in the error. How can I do that?

I could just return a custom array with the error message and data, but I don’t know how to set the status code to 400 in that case?

I’m using Restler 3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:54:58+00:00Added an answer on June 13, 2026 at 12:54 pm

    Responder class is responsible for giving a structure to error response and success response

    You can extend the Responder class as shown below to add data property

    use \Luracast\Restler\Responder;
    use \Luracast\Restler\Defaults;
    
    class MyResponder extends Responder
    {
        public static $data = null;
    
        public function formatError($statusCode, $message)
        {
            $r = array(
                'error' => array(
                    'code' => $statusCode,
                    'message' => $message
                )
            );
            if (isset(self::$data)) {
                $r['data'] = self::$data;
            }
            return $r;
        }
    }
    
    Defaults::$responderClass = 'MyResponder';
    

    And then set the data from your class as shown below

    function put($id, $name)
    {
       try
       {
           product::put($id, $name);
       }
       catch(\util\BadNameException $e)
       {
           MyResponder::$data = product::getNamingConvention();
           throw new RestException(400, "Please supply a better name.");
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it recommended to put a try-catch block in every function that opens a
I'm new to XML. When I try put in some cases into it's XML-parent
I try to print the name of the class that create the new object.
When I put the below function into leon repl , I get java.lang.IllegalArgumentException: Wrong
I've put together a little range function in JS. I've tested it in Chrome
I can put python doctests in the bodies of each function, which I sometimes
What would i need to put in the SortIP function to make the custom
I need to put a one second delay in this jQuery function so that
I have an jquery ajax success function which uses a template to put json
I have put together an image scroller using jquery, like this function rotateImages(whichHolder, start)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.