Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
request = request.header("X-Idempotency-Key", idempotency_key)
}
return try {
apiCall(request.build(), false)
val r = apiCall(request.build(), false)
r.response.close()
r
} catch (resourceNotModified: ResourceNotModified) {
resourceNotModified.printStackTrace()
throw FinalApiException("Resource not modified")
Expand Down Expand Up @@ -374,6 +376,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h

@Throws(ApiException::class)
open fun downloadFile(full_url: String): ApiResponse {
// Caller needs to close response!
var request = Request.Builder()
.url(full_url)
.header("Authorization", "Device $key")
Expand Down Expand Up @@ -438,6 +441,8 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
} catch (e: IOException) {
e.printStackTrace()
throw ApiException("Connection error: " + e.message, e)
} finally {
response.close()
}
}
if (response.code >= 500) {
Expand All @@ -447,6 +452,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
response.close()
throw NotFoundApiException("Server error: Resource not found.")
} else if (response.code == 304) {
response.close()
throw ResourceNotModified()
} else if (response.code == 403) {
response.close()
Expand All @@ -463,6 +469,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
try {
val err = JSONObject(body)
if (err.optString("detail", "") == "Device access has been revoked.") {
response.close()
throw DeviceAccessRevokedException("Device access has been revoked.")
}
} catch (e: JSONException) {
Expand All @@ -480,6 +487,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
response
)
} else {
// Caller needs to close response!
ApiResponse(
null,
response
Expand All @@ -488,7 +496,9 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
} catch (e: JSONException) {
e.printStackTrace()
sentry.captureException(e)
throw ApiException("Invalid JSON received: " + body.take(100), e)
val err = ApiException("Invalid JSON received: " + body.take(100), e)
response.close()
throw err
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class BadgeLayoutSyncAdapter(
}
`is`.close()
os.close()
file.response.close()
result = local_filename
} catch (e: ApiException) {
// TODO: What to do?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class ItemSyncAdapter(
while (inStream.read(buffer).also { byteread = it } != -1) {
outStream.write(buffer, 0, byteread)
}
file.response.close()
inStream.close()
outStream.close()
result = local_filename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ class OrderSyncAdapter(
while ((`is`.read(buffer).also { byteread = it }) != -1) {
os.write(buffer, 0, byteread)
}
file.response.close()
`is`.close()
os.close()
} catch (e: ApiException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ open class SettingsSyncAdapter(
while (inStream.read(buffer).also { byteread = it } != -1) {
outStream.write(buffer, 0, byteread)
}
file.response.close()
inStream.close()
outStream.close()
result = local_filename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class TicketLayoutSyncAdapter(
}
`is`.close()
os.close()
file.response.close()
result = local_filename
} catch (e: ApiException) {
// TODO: What to do?
Expand Down