我正在尝试找出一种准确的方法来检测由于没有互联网连接而导致的 axios 呼叫失败。
axios 调用失败是否返回特定的响应对象或特定的响应状态代码或针对无互联网连接场景抛出特定的错误详细信息?
我将使用“检测由于没有互联网连接而导致的 axios 故障”的示例
try {
const res = await server.get('/auth/user?', {
params: {
refreshToken: refreshToken,
userID: userID
}
}
);
if(res.user.data){
dispatch({type: LOGIN_USER_SUCCESS, payload: res.data.user});
} else {
if(res.axiosFailsDueToNoInternetConnection){
alert('no internet connection');
dispatch({type: RELOAD});
}
}
} catch (error) {
if(error.dueToNoInternetConnection){
alert('no internet connection');
dispatch({type: RELOAD});
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试找出一种安全的方法来在本机反应中保留会话。
我有一些敏感数据,例如从服务器检索的访问令牌,我计划将其设置为 redux 状态。
我不确定设置敏感数据是否安全accessTokenredux 状态)是否安全。
如果不安全,我是否应该将其保存accessToken到设备存储(例如react-native-keychain)accessToken并在每个屏幕请求和服务器请求上加载?
dispatch({type: LOGIN_SUCCESS, payload: {refreshToken, authTimestamp, email} });
Run Code Online (Sandbox Code Playgroud)
const INITIAL_STATE = {
token: {
accessToken: '',
loading: false,
error: ''
}
};
Run Code Online (Sandbox Code Playgroud) 当我在终端中键入"nodemon server.js"命令时,它返回错误"require('update-notifier')({pkg}).notify();".安装的nodemon版本是nodemon@1.17.3
以下是使用的javascript和html.
var express = require('express');
var app = express();
var port = 8888;
app.get('/', function(req, res, next) {
res.sendFile(__dirname + '/index.html');
});
app.listen(port, '0.0.0.0', function() {
console.log('Server running at port ' + port);
});Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<title>My NodeJS Website</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我需要将以下安装后添加到 Podfile。
post_install do |pi|
pi.pods_project.targets.each do |t|
t.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是遇到了这个错误。
[!] Invalid `Podfile` file: [!] Specifying multiple `post_install` hooks is unsupported..
Run Code Online (Sandbox Code Playgroud)
Podfile 中有两个安装后。我应该如何结合它们来解决错误?
post_install do |installer|
flipper_post_install(installer)
end
end
post_install do |pi|
pi.pods_project.targets.each do |t|
t.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
end
end
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用express-validator验证手机号码正则表达式。
我浏览了文档 api,但找不到检查正则表达式的验证器函数。regex.test()像下面这样使用会起作用吗?
body('mobile', 'Invalid mobile number.')
.escape()
.exists({checkFalsy: true})
.isLength({min: 11, max:11})
.regex.test(/^(\+123)\d{11}$/)
Run Code Online (Sandbox Code Playgroud) 我正在尝试在in和的子字段中添加createdAt和updatedAt时间戳otpgenerate: {}verify:{}
我知道使用会将和时间戳{ timestamps: true }添加到整个架构中。createdAtupdatedAt
const userSchema = new mongoose.Schema({
email: { type: String, unique: true },
name: { type: String },
mobileNumber: {
isVerified: {type: Boolean, default: false},
otp: {
generate: {
attempts: {type: Number, default: 0},
total: {type: Number, default: 0},
createdAt: {type: Date},
updatedAt: {type: Date}
},
verify: {
attempts: {type: Number, default: 0},
total: {type: Number, default: 0},
createdAt: {type: Date},
updatedAt: {type: Date} …Run Code Online (Sandbox Code Playgroud) 我有一个注册页面,需要输入用户名和密码才能存储到 mongoDB 中。 
这也会在终端中导致 Mongoose 错误,显示 MongooseError: document must have an _id before save at new MongooseError
下面是代码。
//server.js file
var express = require('express');
var app = express();
var port = 8888;
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
/*Body parser*/
app.use(bodyParser.urlencoded({
extended: true
}));
/*Database connection - MongoDB*/
//Created from the command earlier. Ensure this is done on the first_db instance
var username = 'admin';
var password = '123456';
var dbHost = 'localhost';
var dbPort = '27017'; …Run Code Online (Sandbox Code Playgroud)在React Navigation 5 Auth Flow中,它表示当条件状态发生变化时屏幕将自动导航。
AuthStackNav.js
import React from 'react';
import { connect } from 'react-redux';
import {createStackNavigator} from '@react-navigation/stack';
import AuthScreen from '../screens/AuthScreen';
import HomeScreen from '../screens/HomeScreen';
const AuthStackNav = ({isAuthenticated}) => {
const AuthStack = createStackNavigator();
return (
<AuthStack.Navigator initialRouteName='Auth'>
{
isAuthenticated ?
<AuthStack.Screen name='Home' component={HomeScreen} />
:
<AuthStack.Screen name='Auth' component={AuthScreen} />
}
</AuthStack.Navigator>
);
};
const mapStateToProps = ({isAuthenticated}) => { …Run Code Online (Sandbox Code Playgroud)reactjs react-native react-redux react-navigation react-navigation-v5
customApi.js我正在尝试从使用配置创建的 axios获取 baseURL export default axios.create()。
自定义Api.js 文件
import axios from 'axios';
export default axios.create({
baseURL: 'http://123.123.123.123:5000'
});
Run Code Online (Sandbox Code Playgroud)
我尝试了以下操作,但它控制台记录了undefined。
import api from 'customApi.js';
console.log(api.baseURL);
Run Code Online (Sandbox Code Playgroud)
在自定义配置的 axios 中获取基本 url 的正确方法是什么?
react-native ×5
reactjs ×4
axios ×2
mongodb ×2
mongoose ×2
networking ×2
node.js ×2
cocoapods ×1
ios ×1
javascript ×1
nodemon ×1
react-redux ×1
redux ×1
server ×1
validation ×1