Skip to content

fix: <Injected Response object is undefined> #1206

Open
@schongabor

Description

@schongabor

Description

After upgrading from 9.0.0 to the latest version the objects injected by decorators to controllers are undefined.

import { Response } from 'koa';
import 'reflect-metadata';
import { Get, JsonController, Res } from 'routing-controllers';
import { autoInjectable } from 'tsyringe';

import { Controller } from '../interface';
import { StatusCodes } from 'http-status-codes';

@JsonController('/example')
@autoInjectable()
export class ExampleController implements Controller {
  constructor() {
  }

  @Get()
  async process(@Res() response: Response) {
    console.log('inside controller');     // this is logged ✅
    console.log(response);                   // this is undefined ❌

    response.status = StatusCodes.OK
    response.body = { some: 'response' }

    return response;
  }
}

Expected behavior

Should return the response object

Actual behavior

{
    "name": "TypeError",
    "message": "Cannot set properties of undefined (setting 'status')",
    "stack": "TypeError: Cannot set properties of undefined (setting 'status')\n.....
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions