我编写了一个自定义挂钩,它使用 SWR 从我的 API 检索数据,同时为请求设置“身份验证”标头。
该挂钩对于所有成功的请求都工作正常,但我希望能够处理失败的请求(400 状态代码)。
我可以使用结果访问状态代码,const res = await fetch(url但如何将参数中的错误返回error给挂钩的调用者?
import useSWR from 'swr';
export default function useAPI(path) {
const auth = useAuth();
const { data, error, isValidating, mutate } = useSWR(
!path ? null : `${process.env.NEXT_PUBLIC_API_URL}${path}`,
async (url) => {
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.user.token}`,
accept: 'application/json',
},
});
return res.json();
}
);
return { data, error, isValidating, mutate };
}
Run Code Online (Sandbox Code Playgroud) 我有以下查找检索textScore排序结果的查询,但是如何应用标准只返回文本分数大于1的文档?
db.foods.find(
{ $text: { $search: "red blue green" } },
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )
Run Code Online (Sandbox Code Playgroud) 我想创建一个与JHipster的User实体具有多对一关系的实体.
我已经使用JDL-Studio创建了以下实体和与User的关系,它使用jhipster import-jdl作为.jh文件导入到我的Microservice中:
entity Profile {
name String required
bio String
location String
photo ImageBlob
}
relationship ManyToOne {
Profile{user} to User
}
angularSuffix * with mySuffix
dto * with mapstruct
Run Code Online (Sandbox Code Playgroud)
编译我的Micro服务后,我收到以下错误:
Profile.java:44:错误:找不到符号私有用户用户; symbol:class用户位置:class Profile
ProfileMapper.java:12:错误:找不到符号@Mapper(componentModel ="spring",uses = {UserMapper.class,})符号:class UserMapper
ProfileMapper.java:12:错误:无法检索@Mapper注释@Mapper(componentModel ="spring",uses = {UserMapper.class,})
Profile.java的第43-44行是:
@ManyToOne
private User user;
Run Code Online (Sandbox Code Playgroud)
和ProfileMapper.java如下:
package com.moogrisoft.openseas.service.mapper;
import com.moogrisoft.openseas.domain.*;
import com.moogrisoft.openseas.service.dto.ProfileDTO;
import org.mapstruct.*;
import java.util.List;
/**
* Mapper for the entity Profile and its DTO ProfileDTO.
*/
@Mapper(componentModel = "spring", uses = {UserMapper.class, })
public …Run Code Online (Sandbox Code Playgroud)