Skip to content

Commit 1714b51

Browse files
feature(): improve error messages (missing @controller() decorator)
1 parent 0e788fd commit 1714b51

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

packages/core/errors/messages.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ import { Module } from '../injector/module';
1212
* @param instance The instance which should get the name from
1313
*/
1414
const getInstanceName = (instance: any) =>
15-
(instance && (instance as Type<any>).name);
15+
instance && (instance as Type<any>).name;
1616

1717
/**
1818
* Returns the name of the dependency
1919
* Tries to get the class name, otherwise the string value
2020
* (= injection token). As fallback it returns '+'
2121
* @param dependency The dependency whichs name should get displayed
2222
*/
23-
const getDependencyName = (dependency: InjectorDependency) => getInstanceName(dependency) || dependency || '+';
23+
const getDependencyName = (dependency: InjectorDependency) =>
24+
getInstanceName(dependency) || dependency || '+';
2425
/**
2526
* Returns the name of the module
2627
* Tries to get the class name. As fallback it returns 'current'.
2728
* @param module The module which should get displayed
2829
*/
29-
const getModuleName = (module: Module) => (module && getInstanceName(module.metatype)) || 'current';
30+
const getModuleName = (module: Module) =>
31+
(module && getInstanceName(module.metatype)) || 'current';
3032

3133
export const UNKNOWN_DEPENDENCIES_MESSAGE = (
3234
type: string,
@@ -45,7 +47,9 @@ export const UNKNOWN_DEPENDENCIES_MESSAGE = (
4547

4648
message += ` (`;
4749
message += dependenciesName.join(', ');
48-
message += `). Please make sure that the argument at index [${index}] is available in the ${getModuleName(module)} context.`;
50+
message += `). Please make sure that the argument at index [${index}] is available in the ${getModuleName(
51+
module,
52+
)} context.`;
4953
return message;
5054
};
5155

@@ -61,8 +65,8 @@ export const UNKNOWN_EXPORT_MESSAGE = (text, module: string) =>
6165
export const INVALID_CLASS_MESSAGE = (text, value: any) =>
6266
`ModuleRef cannot instantiate class (${value} is not constructable).`;
6367

64-
export const INVALID_MIDDLEWARE_CONFIGURATION = `Invalid middleware configuration passed inside the module 'configure()' method.`;
65-
export const UNKNOWN_REQUEST_MAPPING = `Request mapping properties not defined in the @RequestMapping() annotation!`;
68+
export const INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`;
69+
export const UNKNOWN_REQUEST_MAPPING = `An invalid controller has been detected. Perhaps, one of your controllers is missing @Controller() decorator.`;
6670
export const UNHANDLED_RUNTIME_EXCEPTION = `Unhandled Runtime Exception.`;
6771
export const INVALID_EXCEPTION_FILTER = `Invalid exception filters (@UseFilters()).`;
6872
export const MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = `Unable to load @nestjs/microservices package. (Please make sure that it's already installed.)`;

0 commit comments

Comments
 (0)