If you want to target in a binary way, one possibility would be to use bit flags in a practice called bit masking.
The operation is quite simple. Let’s say you have 8 error categories, and want to reserve up to 256 possible errors in each category. You can then use a short integer (16 bits) to store all possible errors:
Categoria Erro
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Let’s say the category of bit 0 corresponds to login, and 1 to system:
Categoria Erro Dec Descrição
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 257 Login: Usuário não encontrado
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 258 Login: Senha incorreta
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 513 Sistema: Falha na inicialização
0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 514 Sistema: Erro de configucação
Finally, use AND operations to determine if the error is of a certain category:
Se erro AND 256 = Tipo Login
Se erro AND 512 = Tipo Sistema
One of the advantages of this method is that it allows the creation of elements that fit into 2 or more categories:
0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 771 Sistema/Login: Provedor Oauth não definido
Finally, a simple Javascript implementation:
var cats = {
"login": Math.pow(2, 8), // Bit 9
"sistema": Math.pow(2, 9) // Bit 10
};
console.log(!!(257 & cats.login)); // erro 257 é tipo login,
console.log(!!(257 & cats.sistema)); // porém não tipo sistema.
Sorry to be annoying, but: http://meta.stackexchange.com/a/233676/176034
– Victor Stafusa