homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge
30 lines (29 loc) • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
const constants_1 = require("@nestjs/core/constants");
const ws_exception_1 = require("../errors/ws-exception");
class BaseWsExceptionFilter {
catch(exception, host) {
const client = host.switchToWs().getClient();
this.handleError(client, exception);
}
handleError(client, exception) {
const status = 'error';
if (!(exception instanceof ws_exception_1.WsException)) {
return client.emit('exception', {
status,
message: constants_1.MESSAGES.UNKNOWN_EXCEPTION_MESSAGE,
});
}
const result = exception.getError();
const message = shared_utils_1.isObject(result)
? result
: {
status,
message: result,
};
client.emit('exception', message);
}
}
exports.BaseWsExceptionFilter = BaseWsExceptionFilter;