diff --git a/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt b/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt index b9e26fe..f68f32b 100644 --- a/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt +++ b/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt @@ -3,6 +3,7 @@ package bandcampcollectiondownloader import com.google.gson.Gson import com.google.gson.JsonSyntaxException import com.google.gson.annotations.SerializedName +import org.jsoup.HttpStatusException import org.jsoup.Jsoup import org.zeroturnaround.zip.ZipUtil import java.io.FileOutputStream @@ -125,9 +126,17 @@ fun downloadAll(cookiesFile: Path, bandcampUser: String, downloadFormat: String, val cookies = parsedCookiesToMap(parsedCookies) // Get collection page with cookies, hence with download links - val doc = Jsoup.connect("https://bandcamp.com/$bandcampUser") - .cookies(cookies) - .get() + val doc = try { + Jsoup.connect("https://bandcamp.com/$bandcampUser") + .cookies(cookies) + .get() + } catch (e: HttpStatusException) { + if (e.statusCode == 404) { + throw BandCampDownloaderError("The bandcamp user '$bandcampUser' does not exist.") + } else { + throw Exception("TODO") + } + } println("""Found collection page: "${doc.title()}"""") if (!doc.toString().contains("buy-now")) { println("Provided cookies appear to be working!") diff --git a/src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt b/src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt index bef94c6..bb6c6ac 100644 --- a/src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt +++ b/src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt @@ -39,4 +39,11 @@ class BandcampCollectionDownloaderTests { downloadAll(Paths.get("./test-data/invalidcookies_noarray.json"), "bli", "bli", Paths.get("bli")) } } + + @Test + fun testErrorInvalidBandcampUser() { + assertThrows { + downloadAll(Paths.get("./test-data/wellformedcookies.json"), "zerz1e3687dfs3df7", "bli", Paths.get("bli")) + } + } } \ No newline at end of file diff --git a/test-data/wellformedcookies.json b/test-data/wellformedcookies.json new file mode 100644 index 0000000..5814605 --- /dev/null +++ b/test-data/wellformedcookies.json @@ -0,0 +1,4 @@ +[{ + "Name raw" : "bli", + "Content raw" : "bli" +}] \ No newline at end of file