Issues calling a extension's method

I have a user created extension (instance of IScriptedContentFragmentExtension) with a few methods: one that makes a POST when the user clicks a button on the front-end, and a couple of methods used for debugging. The POST method seems to work, but the debugging methods don't do anything. The code looks like this:

public ServiceResponse GetFromServiceException()
{
    throw new Exception("This is supposed to explode.");
}
 

and the requisite ServiceResponse

public class ServiceResponse : ApiEntity
    {
        public bool Succeeded { get; set; }
        public string ResponseBody { get; set; }
    }

No exception is thrown, at least as far as Admin->Monitoring->Exceptions is concerned. To be specific, nothing is returned from calling the method; I have vm code that does

#set($foo = $extension.Method())
#if($foo && !$foo.hasErrors())
do something with foo
#else
there is not a foo
#end

The widget itself is broken into parts loaded via $core_v2_widget.ExecuteFile(); the other piece of code that seems to be executed is called via POSTing to the .vm file that contains the call to the code (similar to above). Typing the name of the extension in the widget editor shows the correct autocomplete for all the methods available in the extension, so it knows it's there. 

(FWIW the ultimate goal here is to load some information from a private API via a GET - so I don't want to expose it via plain ol' jQuery, but instead have it load and be called by page load behind the scenes)

Any ideas why those methods aren't called? 

Parents
  • Why not just return an empty ServiceResponse, then write the object to the browser just to ensure something is getting called

  • If I have a method that returns a ServiceResponse w/ Succeeded=true, it works; if I return any other thing, it returns null.

    This is true for both the call to the web service, and a "fake" method that simply sets the response body w/o actually doing anything. In both cases, succeeded is true.

    I can tell that the GET call is not being executed because the endpoint shows no hits against it, as well.

  • That is correct you can only return the object you have defined in your velocity extension's method.  That is how it works, you can not pass exceptions or anything else back except the defined return class.  That is why many of our extension methods return a class with AdditionalInfo and Errors collections, these allow us to pass exceptions and other info like "Success" along with the returned object.

    You also need to make sure you are calling your methods with the correct parameters.  If your method expects a Guid, you cannot pass the string representation of a Guid, it has to be a Guid in velocity or the signature won't match and the method won't be called.  That is a potential reason your other method is not being called.

Reply
  • That is correct you can only return the object you have defined in your velocity extension's method.  That is how it works, you can not pass exceptions or anything else back except the defined return class.  That is why many of our extension methods return a class with AdditionalInfo and Errors collections, these allow us to pass exceptions and other info like "Success" along with the returned object.

    You also need to make sure you are calling your methods with the correct parameters.  If your method expects a Guid, you cannot pass the string representation of a Guid, it has to be a Guid in velocity or the signature won't match and the method won't be called.  That is a potential reason your other method is not being called.

Children
No Data