Best way for handle missing args in REST interface in vibed

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 29 07:31:13 PDT 2017


@rootPathFromName
interface API
{
     @path("mytrack")           @method(HTTPMethod.GET)    Json 
doTrackSpeedAnalyze(int trackid, string startDateTime, string 
endDateTime);
}

class MyRouter : API
{
    Config config;
    Database database;
    this(Config config, Database database)
    {
     this.config = config;
     this.database = database;
    }

         @path("/")
         void foo(string _error = null) // I expect that this will 
be called if exception happen in doTrackSpeedAnalyze
         {
             writeln("Error in console"); // does not writing on 
console
         }
      override:
         @errorDisplay!foo
         Json doTrackSpeedAnalyze(int trackid, string 
startDateTime, string endDateTime) // 
/api/mytrack?trackid=123&startDateTime=2000&endDateTime=2010
         {
             if(endDateTime == "0")
             {
                 throw new Exception("Some fields are empty");
             }
             return Json.emptyObject;
         }

}


What I am doing wrong? Should I do  override for foo? Should foo 
present in `interface`?


More information about the Digitalmars-d-learn mailing list