所以我有这个async功能,我可以多次调用 NodeJS 的DNS Api. 前两个调用返回数据,但由于第三个调用,catch 块触发,我没有从前两个调用中获取数据。
由于这完全取决于 query( netflix.com)的类型,因此某些 await 操作可能会因为没有数据而引发错误。但我想要的是我想从其他调用中获取数据,即使其中一些调用存在错误。
这是代码:
const dnsResolve = async () => {
const query = 'netflix.com';
try{
const aRecord = await dns.resolve4(query);
const aaaaRecord = await dns.resolve6(query);
const cnameRecord = await dns.resolveCname(query);
console.log(aRecord);
console.log(aaaaRecord);
console.log(cnameRecord);
}catch(err) {
console.log(err);
}
}
dnsResolve();
Run Code Online (Sandbox Code Playgroud)
上面的代码返回
Error: queryCname ENODATA netflix.com
at QueryReqWrap.onresolve [as oncomplete] (internal/dns/promises.js:167:17) {
errno: undefined,
code: 'ENODATA',
syscall: 'queryCname',
hostname: 'netflix.com'
}
Run Code Online (Sandbox Code Playgroud)
前两个查询的各个输出:
aRecord: [
{ address: '51.73.1.12' }, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个具有多个块和一个管理页面的插件。一切似乎都运转良好。管理页面正在显示,块也正在工作。但是当我进入古腾堡编辑器时,控制台中出现错误,这让我担心我所做的是否错误。
这是错误:
'Block "my-plugin/block-1" is already registered'
'Block "my-plugin/block-2" is already registered'
这是插件 php 文件:
class MY_PLUGIN{
public function __construct() {
add_action( 'admin_menu', [ $this, 'menu_item' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'load_custom_wp_admin_scripts' ] );
add_action( 'init', [ $this, 'register_blocks' ] );
}
/**
* Initialize the plugin
*/
public static function init(){
static $instance = false;
if( !$instance ) {
$instance = new self();
}
return $instance;
}
/**
* Create a new admin page for our app.
*/ …Run Code Online (Sandbox Code Playgroud) 希望你今天过得愉快。因此,我使用 Fetch API 将文件上传到服务器,但我还想在后端包含一个 JSON 字符串。但我无法这样做。
现在这就是我的上传文件功能的样子。如果我只想上传文件而不包含 JSON 字符串,则此方法非常有效:
const uploadFile = ( e ) => {
const uploadedFile = e.target.files[ 0 ];
const formData = new FormData();
formData.append( 'data', uploadedFile );
const rawResponse = await fetch( '/upload-file', {
method: 'POST',
body: formData
});
};
uploadFile();
Run Code Online (Sandbox Code Playgroud)
req.files.data使用;在我的 NodeJS 后端获取文件
但是,如果我包含一个 JSON 字符串并尝试上传文件,那么我的 NodeJS 后端会出现未定义的情况。这是 JSON 字符串的样子:
const uploadFile = ( e ) => {
const uploadedFile = e.target.files[ 0 ];
const formData = new FormData();
const str = 'from …Run Code Online (Sandbox Code Playgroud) 我对 Postgresql 相当陌生,每天都在学习新东西。所以我有一个博客项目,我想使用 PostgreSQL 作为数据库。但我有点陷入最基本的插入查询,该查询引发了错误。我有三个表,posts,authors和categories。我猜我可以正确创建表,但是当我尝试插入数据时出现此错误:
error: syntax error at or near
length: 95,
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '122',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1180',
routine: 'scanner_yyerror'
Run Code Online (Sandbox Code Playgroud)
现在我不知道问题出在哪里,Postgres 的错误也不是那么具体。
谁能告诉我哪里可能出错?
以下是表格:
const createInitialTables = `
CREATE TABLE authors (
id UUID NOT NULL,
author_name VARCHAR(100) NOT NULL UNIQUE CHECK (author_name <> ''),
author_slug VARCHAR(100) NOT NULL …Run Code Online (Sandbox Code Playgroud) express ×3
node.js ×3
javascript ×2
async-await ×1
asynchronous ×1
fetch-api ×1
jquery ×1
php ×1
postgresql ×1
reactjs ×1
sql ×1
wordpress ×1