Skip to content
TORNLIFE More

Error Handling

Started by McNeo [864688] on in API Development.

8 replies · 88 views · thread synced · 7 days ago · View on torn.com
About this thread

Posts archived: 9 / 9 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
9
Discussion span
→
People posting
5
Likes on archived posts
0
Posts by staff, officers and moderators
1
Authority score
72 / 100
Historical score
29 / 100
Story score
24 / 100
Engagement score
45 / 100
McNeo [864688]

The API documentation provides us with a list of error codes, but I ran into a "warning" while looking up the "torn" category with nothing specified for a selection.


{"code":1,"warning":"No default selection for this type"}
Are there any other warnings we can look out for, for the purposes of error handling? Thanks.
cordlesscord1 [1838706]

Is this what you mean?
0 => 'Unknown error' : Unhandled error, should not occur.
1 => 'Key is empty' : Private key is empty in current request.
2 => 'Incorrect Key' : Private key is wrong/incorrect format.
3 => 'Wrong type' : Requesting an incorrect basic type.
4 => 'Wrong fields' : Requesting incorrect selection fields.
5 => 'Too many requests' : Current private key is banned for a small period of time because of too many requests (max 100 per minute).
6 => 'Incorrect ID' : Wrong ID value.
7 => 'Incorrect ID-entity relation' : A requested selection is private (For example, personal data of another user / faction).
8 => 'IP block' : Current IP is banned for a small period of time because of abuse.



McNeo [864688]

Those are the errors, yes, but if you see my OP you'll see a warning, not an error.

I'm wondering if there's other warnings, or any other responses we may get, to use for error handling.
McNeo [864688]

Is there a reason this warning returns:


{"code":1,"warning":"

But the errors return:

{"error":{"code":1

Like, shouldn't the warning return this instead:

{"warning":{"code":1

Just a thought
Mauk [1494436]

And why make it a warning instead of an error? Torn might handle them differently internally, but for public users of the API they are all errors-- no result was available.
McNeo [864688]

I do see the difference there though. It's a difference of "Well shit, something went wrong" versus "You asked for something, but I don't have it."

So error vs. warning vs. information I understand, but the syntaxing should be consistent.
Mauk [1494436]

You're just messing with the semantics at a different level, and every API call will have to check for both errors and warnings because of that.

Both "Well shit, something went wrong" and "You asked for something, but I don't have it" are errors at the API level-- there's no data returned and nothing you can do about it apart from doing a new call with correct parameters.

And also, using your logic 'wrong fields'/selections should be warnings instead of errors.