@joktec/mysql
Version:
JokTec - MySql Service
26 lines • 913 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MysqlCatch = exports.MysqlException = void 0;
const core_1 = require("@joktec/core");
const lodash_1 = require("lodash");
const typeorm_1 = require("typeorm");
class MysqlException extends core_1.InternalServerException {
constructor(msg = 'MYSQL_EXCEPTION', error) {
super(msg, error);
}
}
exports.MysqlException = MysqlException;
exports.MysqlCatch = (0, core_1.BaseMethodDecorator)(async (options) => {
const { method, args } = options;
try {
return await method(...args);
}
catch (err) {
if (err instanceof typeorm_1.QueryFailedError) {
const msg = (0, lodash_1.snakeCase)(err.message).toUpperCase();
throw new MysqlException(msg, err);
}
throw new MysqlException(err, err.message);
}
});
//# sourceMappingURL=mysql.exception.js.map