有时我不喜欢在 kotlin 中嵌套 if else 。有没有办法写出更好的代码?我举一个例子,你可以选择任何其他例子。请分享您的反馈。
suspend fun setStoreImages(call: ApplicationCall) {
val storeImagesMapper = call.receive<ArrayList<StoreImageMapper>>()
val employeeEmail = getEmailFromJWT(call)
if (employeeEmail == null){
call.respond(HttpStatusCode.BadRequest, "No employee email id passed")
}else {
val errorStr = StoreApis.createStoreImages(storeImagesMapper, employeeEmail)
if (errorStr == null) {
call.respond(HttpStatusCode.Created)
} else {
call.respond(HttpStatusCode.BadRequest, errorStr)
}
}
}