thiagobustamante / typescript-rest

This is a lightweight annotation-based expressjs extension for typescript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@PathParam on non-http methods throws invalid http method

lesmo opened this issue · comments

Hi!

First of all, awesome lib. I've been using it in a couple of projects that already reached production and so far it's been delightful.

I noticed an error during a little refactoring I was doing (due to an issue on typescript-rest-swagger to be honest) that killed my entire API (local unit testing, of course):

When using @PathParam (an presumably other decorators) on class methods that do not have an http method decorator, ServerContainer.buildServices() would try to include those methods as part of the API... resulting in an error (somewhat expected) because the method does not have the proper declaration as an http method:

@Path('/some')
class SomeController {
  private someHelper(@PathParam('oops') oops: string) {
    return `we throw invalid http method ${oops}`;
  }

  @GET
  public get() {
    return 'what do you know?';
  }
}

While the problem here is kinda obvious to me now, the error thrown at runtime didn't help much:

Error: Invalid http method for service [/some]

Reading this make you think "well, let's check out SomeController.get() to see if somethings' wrong" and stare at it without much idea about what's wrong, because in fact nothing's wrong in the particular method that should process GET requests.

I'm not pretty sure what would be a good way to improve this experience.