mirror of https://github.com/M66B/FairEmail.git
Gemini: basic error handling
This commit is contained in:
parent
98aea61a37
commit
6470b22c71
|
@ -75,18 +75,42 @@ public class Gemini {
|
||||||
|
|
||||||
JSONObject jresponse = call(context, "POST", path, jrequest);
|
JSONObject jresponse = call(context, "POST", path, jrequest);
|
||||||
|
|
||||||
|
// {
|
||||||
|
// "promptFeedback": {
|
||||||
|
// "blockReason": "SAFETY",
|
||||||
|
// "safetyRatings": [
|
||||||
|
// {
|
||||||
|
// "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||||
|
// "probability": "NEGLIGIBLE"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "category": "HARM_CATEGORY_HATE_SPEECH",
|
||||||
|
// "probability": "NEGLIGIBLE"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "category": "HARM_CATEGORY_HARASSMENT",
|
||||||
|
// "probability": "MEDIUM"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||||
|
// "probability": "NEGLIGIBLE"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
JSONArray jcandidates = jresponse.optJSONArray("candidates");
|
JSONArray jcandidates = jresponse.optJSONArray("candidates");
|
||||||
if (jcandidates == null || jcandidates.length() < 1)
|
if (jcandidates == null || jcandidates.length() < 1)
|
||||||
throw new IOException("candidates missing");
|
throw new IOException(jresponse.toString(2));
|
||||||
JSONObject jcontent = jcandidates.getJSONObject(0).optJSONObject("content");
|
JSONObject jcontent = jcandidates.getJSONObject(0).optJSONObject("content");
|
||||||
if (jcontent == null)
|
if (jcontent == null)
|
||||||
throw new IOException("content missing");
|
throw new IOException(jresponse.toString(2));
|
||||||
JSONArray jparts = jcontent.optJSONArray("parts");
|
JSONArray jparts = jcontent.optJSONArray("parts");
|
||||||
if (jparts == null || jparts.length() < 1)
|
if (jparts == null || jparts.length() < 1)
|
||||||
throw new IOException("parts missing");
|
throw new IOException(jresponse.toString(2));
|
||||||
JSONObject jtext = jparts.getJSONObject(0);
|
JSONObject jtext = jparts.getJSONObject(0);
|
||||||
if (!jtext.has("text"))
|
if (!jtext.has("text"))
|
||||||
throw new IOException("text missing");
|
throw new IOException(jresponse.toString(2));
|
||||||
return new String[]{jtext.getString("text")};
|
return new String[]{jtext.getString("text")};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue