A wish for "failure events" returned by the getEvents API

Hi,

I’m currently testing some Android wrapper updates and hit this error:

2021-09-19 13:27:07.730 27549-27549/com.github.catfriend1.syncthingandroid.debug E/RestApi: getEvents: Skipping event due to JsonSyntaxException, raw=[{"id":20,"globalID":20,"time":"2021-09-19T11:27:03.379654Z","type":"Failure","data":"can't encrypt outgoing data because local data is encrypted (folder-type receive-encrypted)"}]

It doesn’t parse into my error Event.class which is defined like this:

public class Event {

    public int id;
    public int globalID;
    public String type;
    public String time;
    public Map<String, Object> data;

}

Can we please return some “Map<String, Object>” for “data”?

Alternatively, I would have to try…catch that one exceptional error message and parse it into:

public class Event2 {

public int id;
public int globalID;
public String type;
public String time;
public <String> data;

}

Relevant code is at: https://github.com/Catfriend1/syncthing-android/blob/7a4de953bf0ead327c54e4f0144e2f94e1d6fb53/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java#L982

We’ve never really narrowed down the type for data, in principle it could be anything. Looking at our events it is in practice almost always a map/dictionary/object of some kind, like your definition here, with the failure event being an obvious exception. I don’t think the structure of the failure event is essential, this could probably be changed to a {"message": "..."} type thing instead, and we could tighten up the definition to say that the data is always a Map<String, Something>

1 Like

I think you should parse data as Object and then based on the type assume its a map or a string.

1 Like

Would that be a lot of work on your side? I think it’s more easy for people that create wrappers or generally interface the API. I’ve also a batch API event reader in the making, so I’d appreciate going this way.

If not, I’ll take @AudriusButkevicius suggestion and check the type of “Object”.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.