我正在开发一个项目,我们正在从 迁移RestTemplate
到WebClient
.
是WebClient
这样实现的:
try {
...
return webClient
.get()
.uri(someUri)
.retrieve()
.toEntity(SomeBusinessClass.class).block()
} catch(WebClientException e) {
// do some stuff
// want to catch IOExceptions here as well
}
Run Code Online (Sandbox Code Playgroud)
在重构代码时,我也必须重构测试,我遇到了一个测试,在该测试中我们基本上抛出一个ConnectException
来看看我们的内部代码是否根据我们的需要捕获它们。通过RestTemplate
的异常类,我们能够像这样定义异常:
ResourceAccessException exc = new ResourceAccessException("I/O error on GET request", new ConnectException("Connection refused: connect"))
Run Code Online (Sandbox Code Playgroud)
WebClient
我尝试对提供的异常类执行相同的操作WebClientException
,但这是一个抽象类,唯一继承它的类WebClientResponseException
并且不提供允许执行相同操作的构造函数。所以我唯一的选择是这样做RuntimeException
:
RuntimeException exc = new RuntimeException("I/O error on GET request", new ConnectException("Connection refused: connect"))
Run Code Online (Sandbox Code Playgroud)
但是,由于我不想重写我们的内部代码来捕获RuntimeException
级别上的异常WebClientException
,所以这不是一个选项,我想知道如何做到这一点?
我试图在 …
我想在我的项目中实现退出方法。我观看了所有 youtube 教程,但似乎导航抽屉是更新版本。我对如何将这些注销编码实施到我的编码中一无所知。
最新版本的导航抽屉已经内置在 ui 包文件夹中。所以我不太确定如何实现这些教程代码,因为大多数教程代码都有这个代码。下面是教程代码,我不知道如何将注销方法实现到我的 home.java 代码中。谢谢你
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
getSupportActionBar().setTitle("Home");
getSupportFragmentManager().beginTransaction().replace(R.id.container,new HomeFragment()).commit();
} else if (id == R.id.nav_profile) {
getSupportActionBar().setTitle("Profile");
getSupportFragmentManager().beginTransaction().replace(R.id.container,new ProfileFragment()).commit();
} else if (id == R.id.nav_settings) {
getSupportActionBar().setTitle("Settings");
getSupportFragmentManager().beginTransaction().replace(R.id.container,new SettingsFragment()).commit();
}
else if (id == R.id.nav_signout) {
FirebaseAuth.getInstance().signOut();
Intent loginActivity = new Intent(getApplicationContext(),LoginActivity.class);
startActivity(loginActivity);
finish();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Run Code Online (Sandbox Code Playgroud)
这是我的 …
java android firebase navigation-drawer firebase-authentication
我正在尝试制作一个聊天应用程序,该应用程序可以拥有最多两个用户的聊天室。我有一个包含两个用户 ID 的chatrooms
数组字段的集合和聊天室文档members
。在创建新聊天室之前知道我想检查两个特定用户是否已经一起使用了聊天室,因此我需要使用我的文档查询两个用户 ID。
最后,我只想检查聊天室是否存在,然后返回 false,然后尝试使用相同的两个特定用户 ID 创建另一个聊天室。
我的问题是数组内容的查询。
我试过
chatroomsCollection.where('members', '==', firstUserID).where('members', '==', secondUserID).limit(1).get()
Run Code Online (Sandbox Code Playgroud)
并尝试
chatroomsCollection.where('members','array-contains', firstUserID).where('members', 'array-contains', secondUserID).limit(1).get()
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
甚至可以在 noSQL 中使用数组内的元素查询多个字符串吗?
我试图将表单 firebaseuser 更改为 authresults
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
abstract class AuthImplementaion {
}
class Auth implements AuthImplementaion {
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
Future<String> SignIn(String _email, String _password) async{
FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(email: _email, password: _password);
return user.uid;
}
}
Run Code Online (Sandbox Code Playgroud)
消息:无法将“AuthResult”类型的值分配给“FirebaseUser”类型的变量。尝试更改变量的类型,或将右侧类型转换为“FirebaseUser”
我已经查了很多其他问题,但没有一个有效。
我正在尝试创建一个异步验证器来检查输入的用户名是否已经存在。但是每当我在输入字段中输入字母时,我都会收到一条错误消息,指出我的userService
实例是undefined
.
以下是我的UserService
:
export interface UsernameCheck {
info: string,
usernameAvailable: boolean;
}
@Injectable({
providedIn: 'root'
})
export class UserService {
private apiUrl = 'http://localhost:5001/project-f-angular/us-central1';
constructor(
private http: HttpClient
) { }
checkUsername(username: string) {
const params = new HttpParams().set('username', username);
return this.http.get<UsernameCheck>(`${this.apiUrl}/checkUsername`, {params});
}
}
Run Code Online (Sandbox Code Playgroud)
http 请求指向本地运行的 Firebase Cloud Functions 模拟器。
这是我正在使用它的组件:
export class SignUpComponent implements OnInit {
signUpForm: FormGroup;
constructor(
private userService: UserService,
private formBuilder: FormBuilder) {
}
ngOnInit() {
this.signUpForm = this.formBuilder.group({ …
Run Code Online (Sandbox Code Playgroud)