Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Mysql Error #2447

Open
gavin-c-tcg opened this issue Dec 30, 2020 · 0 comments
Open

Check Mysql Error #2447

gavin-c-tcg opened this issue Dec 30, 2020 · 0 comments
Labels

Comments

@gavin-c-tcg
Copy link

Maybe can add some utility to check mysql Error

import * as MysqlErrorCode from 'mysql/lib/protocol/constants/errors';

/**
 * MysqlErrorCode like {
 *  "163": "HA_ERR_FOREIGN_DUPLICATE_KEY",
 *  "HA_ERR_FOREIGN_DUPLICATE_KEY": 163,
 * }
 */
export const isMySQLErrorCode = (code: string) => {
    return typeof code === 'string' && typeof MysqlErrorCode?.[code] === 'number';
};
class MySQLError extends Error{ }
error.isMySqlError = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants