vulcainjs / vulcain-corejs

Microservice framework for nodejs
https://vulcainjs.github.io
Apache License 2.0
11 stars 3 forks source link

Throw error are not sent on body response #17

Closed workfel closed 7 years ago

workfel commented 7 years ago

Hi,

I use a command for make a request, but during the command i have an error. So i wrapping my code with try catch and i want to send the error in response body. But no error was displayed. Only error 500.

{
    "tenant": "vulcain",
    "schema": "User",
    "action": "createuser",
    "domain": "madelink",
    "status": "Error",
    "correlationId": "a310c885a95640ce8bddb4b8aac05a07",
    "error": {}
}

My command:

@Command({ executionTimeoutInMilliseconds: 3500 })
class UserCreationKeycloakCommand extends AbstractHttpCommand implements IUserCreationKeycloakCommand {
    private myvalue: IDynamicProperty<string>;

    constructor( @Inject(DefaultServiceNames.Container) container: IContainer, @Inject('KeycloakService') private service: KeycloakService) {
        super(container);
    }

    // Execute command
    async runAsync(user: User): Promise<UserKeycloak> {
        let client: KeycloakClient = await this.service.onConnectAdminClientAsync();
        try {
            let clientCreated = await client.users.create(this.service.realmKeycloak, this.service.convertUser(user));

            return clientCreated;
        } catch (error) {
            console.log('Error create user keycloak', error);
            throw error;
        }
    }
}

And my handler:

 @Action({ description: "Create a new user.", outputSchema: "any", inputSchema: "User" }) // action = method name (minus Async)
    async createUserAsync(user: User): Promise<any> {
        // Creation in keycloak
        const cmd = await this.createCommandAsync("UserCreationKeycloakCommand");
        let userKeycloakCreated = await cmd.runAsync<UserKeycloak>(user);

       return {
            keycloak: userKeycloakCreated
        };

    }

Thx

malain commented 7 years ago

error must have a 'message' property

workfel commented 7 years ago

Yes, thank you, it's working