Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve robustness when building Codacy API base URL #42

Merged
merged 1 commit into from
Jan 26, 2021
Merged
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
3 changes: 2 additions & 1 deletion src/main/scala/com/codacy/api/client/CodacyClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.codacy.api.client
import play.api.libs.json._
import com.codacy.api.util.JsonOps
import scalaj.http.Http
import java.net.URL

import scala.util.{Failure, Success, Try}
import scala.util.control.NonFatal
Expand All @@ -25,7 +26,7 @@ class CodacyClient(
apiToken.map(t => "api_token" -> t) ++
projectToken.map(t => "project_token" -> t)

private val remoteUrl = apiUrl.getOrElse("https://api.codacy.com") + "/2.0"
private val remoteUrl = new URL(new URL(apiUrl.getOrElse("https://api.codacy.com")), "/2.0").toString()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lolgab, perhaps you have a suggestion on how to do this in a more "Scala way"? 😄

We should also have some error handling here in case the URL coming from user input is malformed. 🤔 Can you help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is fine.. I was thinking about files, that's why I told you there was a "Scala way" to interpolate 😄
I'm merging this one.


/*
* Does an API request and parses the json output into a class
Expand Down