Skip to content

Commit

Permalink
Merge pull request #28 from Ferlab-Ste-Justine/fix/cqdg-752_fix_message
Browse files Browse the repository at this point in the history
fix: CQDG-752 fix unauthorized message
  • Loading branch information
adipaul1981 authored Jun 17, 2024
2 parents 8130718 + faa3d0b commit 0361e85
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/ca/ferlab/ferload/client/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import picocli.CommandLine.Command
import java.io.File

@Command(name = "ferload-client", mixinStandardHelpOptions = true,
version = Array("2.1.0"),
version = Array("2.1.1"),
description = Array("Official Ferload Client command line interface for files download."),
subcommands = Array(classOf[Configure], classOf[Download]))
class Main extends Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ abstract class BaseHttpClient {
s"$message, code: $status, message:\n${msg.getOrElse("")}"
}

protected def formatUnauthorizedMessage(message: String, body: Option[String]): String = {
val msg = body.map(r => new JSONObject(r).get("msg"))

s"$message\n${msg.getOrElse("")}"
}


protected def toMap(body: Option[String], lineContents: Seq[LineContent]): Map[LineContent, String] = {
body.map(new JSONObject(_).toMap.asScala.map({ case (key, value) =>
lineContents.find(_.filePointer == key).get -> value.toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FerloadClient(userConfig: UserConfig) extends BaseHttpClient with IFerload
val (body, status) = executeHttpRequest(httpRequest)
status match {
case 200 => toMap(body, manifestContent.lines)
case 403 => throw new UnauthorizedException(formatExceptionMessage("No enough access rights to download the following files", status, body))
case 403 => throw new UnauthorizedException(formatUnauthorizedMessage("The manifest contains files you don't have access to. Please review the following unauthorized file IDs:", body))
case _ => throw new IllegalStateException(formatExceptionMessage("Failed to retrieve download link(s)", status, body))
}
}
Expand Down

0 comments on commit 0361e85

Please sign in to comment.