我在客户端使用 React + Redux,后端在 NET CORE 中。客户端使用以下 API 从 API 获取数据:
return fetch(`api/login`, requestOptions)
.then(response => {
if(!response.ok) {
return Promise.reject(response.json() as Promise<AuthError>);
} else {
return response.json() as Promise<ILoginResponse>
}
})
Run Code Online (Sandbox Code Playgroud)
请求选项有:
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
};
Run Code Online (Sandbox Code Playgroud)
当密码错误时,服务器返回
404 Bad request
Run Code Online (Sandbox Code Playgroud)
身体是:
{"errorCode":2,"description":"Invalid Password"}
Run Code Online (Sandbox Code Playgroud)
我想读取正文,但使用这段代码是不可能的,因为这response.json() as Promise<AuthError>会产生一个空对象。有没有办法读取错误请求响应的正文?
是否可以将已发布的.NET Core 2.0应用程序转换为.deb文件?我通过发布了我的应用dotnet publish -c Release -r ubuntu.16.04-x64。现在,我的目标是拥有一个可以在Ubuntu计算机上安装的deb文件。
在我的 react-redux-typescript 应用程序中,我有多个子状态构成应用程序状态。申请状态如下。
interface AppState {
dialogs: DialogState,
messages: MessageState,
notifications: NotificationsState,
errors: ErrorState
loading: LoadingState,
status: StatusState;
}
Run Code Online (Sandbox Code Playgroud)
我使用connect方法将 React 组件中可用的子状态之一作为props. 但是现在我有一个案例,我需要一个组件中的两个子状态属性作为它的props.
具体这些部分:
interface LoadingState {
size: number
available: boolean
}
interface StatusState {
name: string
}
Run Code Online (Sandbox Code Playgroud)
通常,我在组件Loading中使用connect方法如下:
export default connect(
(state: AppState) => state.loading, actionCreators)(Loading);
Run Code Online (Sandbox Code Playgroud)
Loading 组件的头部是:
type LoadingProps = LoadingState & typeof actionCreators;
class Loading extends React.Component<LoadingProps, {}>
Run Code Online (Sandbox Code Playgroud)
如果我这样做,我就有了LoadingState可用作道具的界面属性。但是,如果我还想要StatusState在同一组件中作为 props 使用的属性,我该怎么办?
reactjs ×2
redux ×2
.net ×1
.net-core ×1
connect ×1
ecmascript-6 ×1
es6-promise ×1
javascript ×1
react-redux ×1
ubuntu ×1