Include name/alias of already existing (pending) contact in error

This commit is contained in:
Nico Alt
2021-02-13 12:00:00 +00:00
parent 7fab97d26c
commit d095ba0b15
4 changed files with 35 additions and 8 deletions

View File

@@ -112,11 +112,13 @@ constructor(
return ctx.json(details)
} catch (e: ContactExistsException) {
ctx.status(FORBIDDEN_403)
val details = mapOf("error" to "CONTACT_EXISTS")
val details =
mapOf("error" to "CONTACT_EXISTS", "remoteAuthorName" to e.remoteAuthor.name)
return ctx.json(details)
} catch (e: PendingContactExistsException) {
ctx.status(FORBIDDEN_403)
val details = mapOf("error" to "PENDING_EXISTS")
val details =
mapOf("error" to "PENDING_EXISTS", "pendingContactAlias" to e.pendingContact.alias)
return ctx.json(details)
}
return ctx.json(pendingContact.output())

View File

@@ -135,6 +135,7 @@ class ContactControllerIntegrationTest: IntegrationTest() {
response = post("$url/contacts/add/pending", json)
assertEquals(403, response.statusCode)
assertEquals("PENDING_EXISTS", response.jsonObject.getString("error"))
assertEquals(alias, response.jsonObject.getString("pendingContactAlias"))
}
@Test

View File

@@ -183,8 +183,15 @@ internal class ContactControllerTest : ControllerTest() {
link,
alias
)
} throws ContactExistsException(null, null)
every { ctx.json(mapOf("error" to "CONTACT_EXISTS")) } returns ctx
} throws ContactExistsException(null, author)
every {
ctx.json(
mapOf(
"error" to "CONTACT_EXISTS",
"remoteAuthorName" to author.name
)
)
} returns ctx
controller.addPendingContact(ctx)
verify { ctx.status(403) }
}
@@ -204,8 +211,15 @@ internal class ContactControllerTest : ControllerTest() {
link,
alias
)
} throws PendingContactExistsException(null)
every { ctx.json(mapOf("error" to "PENDING_EXISTS")) } returns ctx
} throws PendingContactExistsException(pendingContact)
every {
ctx.json(
mapOf(
"error" to "PENDING_EXISTS",
"pendingContactAlias" to pendingContact.alias
)
)
} returns ctx
controller.addPendingContact(ctx)
verify { ctx.status(403) }
}