Skip to content
TORNLIFE More

Inconsistent API error results for chain reports

Started by saxasm [2720534] on in Bugs & Issues.

6 replies · 88 views · thread synced · 4 days ago · View on torn.com
About this thread

Posts archived: 7 / 7 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
7
Discussion span
→
People posting
4
Likes on archived posts
4
Posts by staff, officers and moderators
5
Authority score
59 / 100
Historical score
35 / 100
Story score
38 / 100
Engagement score
47 / 100

Most-liked replies

saxasm [2720534]
If I try to request the chain report for chain 13, I get the following structure of error message:



{
"success": [
false
],
"msg": [
"This report is no longer available"
]
}


As far as I know, this used to be the shape of all error results from the chain report API, so you could check for failure by looking if there is a "success" field set to false.

However, now, if I try to request the chain report for chain 1300000000, I instead get the following structure of error:


{
"code": [
6
],
"error": [
"Incorrect ID"
]
}


It seems really strange that the API should report errors with two different structures of error message, so I have to try two different things to check if there was an error. This must be something that was overlooked in changing the chain report API at some point, right? I'd really like it if error results had consistently named fields...
Chedburn [1] Admin Developer
One error is to say that the chain did exist, but the report has been pruned, the other error is to say that the chain doesn't exist at all.
We could merge them into the same error, as "This chain is not available", but I don't really see the harm of this?
saxasm [2720534]
My problem isn't really that they are different error messages - that makes sense - but that the names of the fields in the error message are different, so there's no clean way to check if I got an error back - there is no one field that is guaranteed to exist whenever there was an error.

The change I'd suggest is that either both errors have the structure "success" / "message" or both have the structure "error" / "code" - I think the latter is more consistent with how the API gives errors for other things, but the most important thing is I think to be consistent.

In fact, the most consistent thing would be to have it return not

{
"chainreport": {
"code": [
6
],
"error": [
"Incorrect ID"
]
}
}

but

{
"error": {
"code": 6,
"error": "Incorrect ID",
},
}

since that is how an Incorrect ID error appears for every other API endpoint.
Chedburn [1] Admin Developer
I think the pain is that one error is being produced outside of the API by the faction chains handler.
I can ask Sergey perhaps to check if there's any simple avenue to resolve this.