Skip to content

Commit 4001d85

Browse files
committed
fix: handle exceptions in CNPJ validation logic
1 parent 555ead5 commit 4001d85

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/cnpjValidator/cnpjValidator2.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,17 @@ function cnpjIsValid(
109109
};
110110
}
111111

112-
if (isValid(cnpj)) {
112+
try {
113+
if (isValid(cnpj)) {
114+
return {
115+
isValid: true,
116+
errorMsg: null,
117+
};
118+
}
119+
} catch {
113120
return {
114-
isValid: true,
115-
errorMsg: null,
121+
isValid: false,
122+
errorMsg: getErrorMessage(2), // 'CNPJ is not valid'
116123
};
117124
}
118125

0 commit comments

Comments
 (0)