Disregard responseCode from framework

This commit is contained in:
Mygod
2021-05-07 14:15:45 -04:00
parent 52039de0a4
commit 919bfe93dc

View File

@@ -46,10 +46,13 @@ object MacLookup {
val work = Work(url.openConnection() as HttpURLConnection) val work = Work(url.openConnection() as HttpURLConnection)
work.job = GlobalScope.launch(Dispatchers.IO) { work.job = GlobalScope.launch(Dispatchers.IO) {
try { try {
while (work.conn.responseCode != 200) { var response: String
if (work.conn.responseCode != 429) { var obj: JSONObject
throw UnexpectedError(mac, work.conn.inputStream.bufferedReader().readText()) while (true) {
} response = work.conn.inputStream.bufferedReader().readText()
obj = JSONObject(response)
if (obj.getBoolean("success")) break
if (obj.getInt("errorCode") != 429) throw UnexpectedError(mac, response)
work.conn = url.openConnection() as HttpURLConnection work.conn = url.openConnection() as HttpURLConnection
delay(max(1, work.conn.getHeaderField("Retry-After")?.toLongOrNull().let { delay(max(1, work.conn.getHeaderField("Retry-After")?.toLongOrNull().let {
if (it == null) { if (it == null) {
@@ -59,9 +62,6 @@ object MacLookup {
} else it } else it
}) * 1000) }) * 1000)
} }
val response = work.conn.inputStream.bufferedReader().readText()
val obj = JSONObject(response)
if (!obj.getBoolean("success")) throw UnexpectedError(mac, response)
if (!obj.getBoolean("found")) { if (!obj.getBoolean("found")) {
// no vendor found, we should not retry in the future // no vendor found, we should not retry in the future
AppDatabase.instance.clientRecordDao.upsert(mac) { macLookupPending = false } AppDatabase.instance.clientRecordDao.upsert(mac) { macLookupPending = false }