@@ -106,12 +106,22 @@ class LocationSetter(appContext: Context, workerParams: WorkerParameters) : Coro
106
106
notifyError(e.readableMessage)
107
107
Result .failure()
108
108
}
109
- private fun notifyErrors (response : String , json : JSONObject ? = null) = notifyError(try {
110
- val errors = (json ? : JSONObject (response)).getJSONArray(" errors" )
111
- (0 until errors.length()).joinToString(" \n " ) { errors.getJSONObject(it).getString(" message" ) }
112
- } catch (e: JSONException ) {
113
- response
114
- })
109
+ private fun notifyErrors (response : String , json : JSONObject ? = null): Boolean {
110
+ var shouldWarn = true
111
+ notifyError(try {
112
+ val errors = (json ? : JSONObject (response)).getJSONArray(" errors" )
113
+ (0 until errors.length()).joinToString(" \n " ) {
114
+ val error = errors.getJSONObject(it)
115
+ if (error.optJSONObject(" extensions" )?.optString(" code" ) == " INTERNAL_SERVER_ERROR" ) {
116
+ shouldWarn = false
117
+ }
118
+ error.getString(" message" )
119
+ }
120
+ } catch (e: JSONException ) {
121
+ response
122
+ })
123
+ return shouldWarn
124
+ }
115
125
private suspend fun doWork (lat : Double , lon : Double , time : Long , apiUrl : String , conn : HttpURLConnection ): Result {
116
126
return when (val code = conn.responseCode) {
117
127
200 -> {
@@ -120,10 +130,7 @@ class LocationSetter(appContext: Context, workerParams: WorkerParameters) : Coro
120
130
val obj = JSONObject (response)
121
131
val webhook = obj.getJSONObject(" data" ).optJSONObject(" webhook" )
122
132
if (webhook == null ) {
123
- notifyErrors(response, obj)
124
- if (obj.optJSONObject(" extensions" )?.optString(" code" ) == " INTERNAL_SERVER_ERROR" ) {
125
- Timber .w(response)
126
- } else Timber .w(Exception (response))
133
+ if (notifyErrors(response, obj)) Timber .w(response) else Timber .w(Exception (response))
127
134
return Result .retry()
128
135
}
129
136
if (webhook[" human" ] == JSONObject .NULL ) {
0 commit comments