Skip to content

Commit

Permalink
reddit error handling (#12)
Browse files Browse the repository at this point in the history
* reddit error handling

* precommit hook on all modules
  • Loading branch information
psuzn authored Aug 3, 2023
1 parent 2976219 commit 7057b87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.sujanpoudel.playdeals.jobs
import io.vertx.core.json.JsonObject
import io.vertx.ext.web.client.WebClient
import io.vertx.ext.web.client.WebClientOptions
import io.vertx.kotlin.core.json.jsonArrayOf
import io.vertx.kotlin.coroutines.await
import me.sujanpoudel.playdeals.common.SIMPLE_NAME
import me.sujanpoudel.playdeals.common.loggingExecutionTime
Expand Down Expand Up @@ -85,7 +86,14 @@ class RedditPostsScrapper(
return webClient.get(path)
.send()
.map {
it.bodyAsJsonObject().getJsonObject("data").getJsonArray("children")
if (it.statusCode() == 200) {
it.bodyAsJsonObject()
.getJsonObject("data")
.getJsonArray("children")
} else {
log.error("Error while getting reddit post : ${it.bodyAsString()}")
jsonArrayOf()
}
}
.map { posts ->
posts.map { post ->
Expand Down
9 changes: 4 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ allprojects {
jvmTarget = "17"
}
}

task("preCommitHook") {
dependsOn(tasks.ktlintCheck)
}
}

tasks.withType<Test> {
Expand All @@ -49,11 +53,6 @@ tasks.withType<Test> {
}
}

task("preCommitHook") {
dependsOn(tasks.ktlintFormat)
dependsOn(tasks.ktlintCheck)
}

task("installPreCommitHook") {
delete(File(projectDir, ".git/hooks/pre-commit"))
copy {
Expand Down

0 comments on commit 7057b87

Please sign in to comment.