I'm designing a backend webservice, and when an error occurs I'm returning it as a JSON to the frontend. This JSON contains an error code, which the frontend maps to an localized string and shows that to the user.
Should my error codes be strings or integers?
{
"error": {
"code": 9900,
"message": "Invalid ID"
}
}
OR
{
"error": {
"code": "9900",
"message": "Invalid ID"
}
}
I'm thinking integers myself, but I'm just wondering if maybe returning fixed length error codes would be more correct, like if I atm have error codes like 9900, 9901, and in the future I wanna send the code 12, would it be correct to send them as "9900"
, "9901"
, and "0012"
, vs 9900
, 9901
, and 12
.
"9900"
,"9901"
, and"0012"
, vs9900
,9901
, and12
.