Skip to content

Commit 6d3813e

Browse files
committed
review fix
1 parent 2a7bf38 commit 6d3813e

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed

src/main/kotlin/com/vk/admstorm/actions/CreateHasteAction.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class CreateHasteAction : AdmActionBase() {
2020

2121
executeOnPooledThread {
2222
val link = HastebinService.getInstance(e.project!!).createHaste(copyText)
23-
var isUnavailable = false
2423

25-
if (link != null) {
24+
val text = if (link != null) {
2625
MyUtils.copyToClipboard(link)
26+
"Link to hastebin copied to clipboard"
2727
} else {
28-
isUnavailable = true
28+
"Hastebin service unavailable. Try again later"
2929
}
3030

3131
AdmNotification()
32-
.withTitle(if (isUnavailable) "Hastebin service unavailable. Try again later" else "Link to hastebin copied to clipboard")
32+
.withTitle(text)
3333
.show()
3434
}
3535
}

src/main/kotlin/com/vk/admstorm/actions/SendLogsToHastebinAction.kt

+10-9
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@ class SendLogsToHastebinAction : AdmActionBase() {
1212
val project = e.project ?: return
1313
val hasteLink = HastebinService.getInstance(project).createHaste(readIdeaLogFile())
1414

15-
val notification = if (hasteLink != null) {
16-
AdmNotification("Thanks for logs!")
17-
.withTitle("Logs successfully sent to Hastebin")
18-
.withActions(AdmNotification.Action("Copy hastebin link") { _, notification ->
19-
MyUtils.copyToClipboard(hasteLink)
20-
notification.expire()
21-
})
22-
} else {
15+
if (hasteLink == null) {
2316
AdmNotification()
2417
.withTitle("Hastebin service unavailable. Try again later")
18+
.show(project)
19+
return
2520
}
2621

27-
notification.show(project)
22+
AdmNotification("Thanks for logs!")
23+
.withTitle("Logs successfully sent to Hastebin")
24+
.withActions(AdmNotification.Action("Copy hastebin link") { _, notification ->
25+
MyUtils.copyToClipboard(hasteLink)
26+
notification.expire()
27+
})
28+
.show(project)
2829
}
2930

3031
override fun beforeUpdate(e: AnActionEvent) {

src/main/kotlin/com/vk/admstorm/executors/BaseRemoteExecutor.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ abstract class BaseRemoteExecutor(protected val project: Project, toolName: Stri
9191
executeOnPooledThread {
9292
val output = outputListener.output.stdout + outputListener.output.stderr
9393
val link = HastebinService.getInstance(e.project!!).createHaste(output)
94-
var isUnavailable = false
9594

96-
if (link != null) {
95+
val text = if (link != null) {
9796
copyToClipboard(link)
97+
"Link to hastebin copied to clipboard"
9898
} else {
99-
isUnavailable = true
99+
"Hastebin service unavailable. Try again later"
100100
}
101101

102102
AdmNotification()
103-
.withTitle(if (isUnavailable) "Hastebin service unavailable. Try again later" else "Link to hastebin copied to clipboard")
103+
.withTitle(text)
104104
.show()
105105
}
106106
}

src/main/kotlin/com/vk/admstorm/playground/KphpPlaygroundWindow.kt

+11-11
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ require_once 'vendor/autoload.php';
129129

130130
executeOnPooledThread {
131131
val link = HastebinService.getInstance(myProject).createHaste(content)
132-
if (link != null) {
133-
MyUtils.copyToClipboard(link)
134-
135-
invokeLater {
136-
myShareLabel.text = "Link copied"
137-
myShareLabel.isVisible = true
138-
invokeAfter(2000) {
139-
myShareLabel.isVisible = false
140-
}
141-
}
142-
} else {
132+
if (link == null) {
143133
AdmNotification()
144134
.withTitle("Hastebin service unavailable. Try again later")
145135
.show()
136+
return@executeOnPooledThread
137+
}
138+
139+
MyUtils.copyToClipboard(link)
140+
invokeLater {
141+
myShareLabel.text = "Link copied"
142+
myShareLabel.isVisible = true
143+
invokeAfter(2000) {
144+
myShareLabel.isVisible = false
145+
}
146146
}
147147
}
148148
}

src/main/kotlin/com/vk/admstorm/services/HastebinService.kt

+11-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.vk.admstorm.env.getByKey
1010
import kotlinx.serialization.json.Json
1111
import kotlinx.serialization.json.JsonObject
1212
import kotlinx.serialization.json.jsonPrimitive
13+
import java.net.HttpURLConnection
1314
import java.net.URI
1415
import java.net.http.HttpClient
1516
import java.net.http.HttpRequest
@@ -39,27 +40,27 @@ class HastebinService {
3940
val request = HttpRequest.newBuilder()
4041
.uri(URI.create("$hastLink/documents"))
4142
.POST(HttpRequest.BodyPublishers.ofString(data))
42-
.timeout(Duration.ofSeconds(10)).build()
43+
.timeout(Duration.ofSeconds(10))
44+
.build()
4345

4446
val response = httpClient.send(request, HttpResponse.BodyHandlers.ofString())
45-
if (response.statusCode() != 200) {
46-
LOG.error(
47-
"Something wrong with Hastebin service:" +
48-
" status code ${response.statusCode()}, error: ${response.body()}"
49-
)
47+
if (response.statusCode() != HttpURLConnection.HTTP_OK ) {
48+
LOG.error("Error sending the request (status code: ${response.statusCode()}, body: ${response.body()})")
5049
return null
5150
}
5251

5352
val jsonResponse = Json.parseToJsonElement(response.body())
5453
if(jsonResponse !is JsonObject){
55-
LOG.error(
56-
"Something wrong with Hastebin service:" +
57-
" status code ${response.statusCode()}, error: ${response.body()}"
58-
)
54+
LOG.error("Error parsing the request (body: ${response.body()})")
5955
return null
6056
}
6157

6258
val value = jsonResponse["key"]?.jsonPrimitive?.content
59+
if (value == null) {
60+
LOG.error("JsonResponse returned null value")
61+
return null
62+
}
63+
6364
return "$hastLink/${value}"
6465
}
6566
}

0 commit comments

Comments
 (0)