我想通过 article_id 使用 knex 从文章表中删除。这已经作为外键存在于评论表中。
如何测试数据是否已被删除以及如何将其发送给用户。
我决定通过编写一个函数来解决这个问题,用 .then 从两个函数中删除。这看起来像我在正确的路线上吗?
exports.deleteArticleById = function (req, res, next) {
const { article_id } = req.params;
return connection('comments')
.where('comments.article_id', article_id)
.del()
.returning('*')
.then((deleted) => {
console.log(deleted);
return connection('articles')
.where('articles.article_id', article_id)
.del()
.returning('*');
})
.then((article) => {
console.log(article);
return res.status(204).send('article deleted');
})
.catch(err => next(err));
};
Run Code Online (Sandbox Code Playgroud)
目前,我通过日志获得了正确的数据,但状态为 500,但我认为我需要尝试获得 204?
任何帮助将非常感激。
我正在尝试使用 dotnet SDK 将 base64 pdf 上传到 S3。文件正在上传,但显示为空白 pdf。我错过了什么吗?
我认为问题可能与我上传的方式有关?我尝试过仅使用 illustrationDocumentBody 并将其作为字节发送。illustrationDocumentBody 本身上传文件,但当我尝试在 S3 中查看它时,我无法加载 pdf。
try
{
await s3Client.PutObjectAsync(new PutObjectRequest
{
ContentBody = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(illustrationDocumentBody)),
ContentType = "application/pdf",
BucketName = Environment.GetEnvironmentVariable("ESIS_SYNC_BUCKET"),
Key = $"Opportunities/{oppName}/ESIS-{brokerName}-{productCode}-{customerName}.pdf",
CannedACL = S3CannedACL.BucketOwnerFullControl
});
}
catch (AmazonS3Exception e)
{
Console.WriteLine(
"Error encountered ***. Message:'{0}' when writing an object", e.Message);
}
catch (Exception e)
{
Console.WriteLine(
"Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
}
Run Code Online (Sandbox Code Playgroud)
我希望能够查看 PDF,但它上传的是空白 PDF。Sendgrid 也使用 base64 字符串作为电子邮件发送,并且它正在工作,所以我认为它与 base64 字符串无关。
我有一个故意抛出错误的组件,包裹在错误边界组件中。
它捕获错误并显示消息,但只显示一秒钟。
这是我的包装组件
useEffect(() => {
error();
}, []);
const error = () => {
try {
return [].replace(/'--'/, '')
} catch (error) {
throw(error)
}
}
Run Code Online (Sandbox Code Playgroud)
和我的错误边界组件
class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
console.log('derived', error)
// Update state so the next render will show the fallback UI.
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
console.log('error did catch', error)
this.setState({ hasError: true})
}
render() {
if …
Run Code Online (Sandbox Code Playgroud) 我用 JavaScript 编写了一个函数来放大按钮并立即缩小到原始大小。
\n\n它可以使用其他 CSS 属性来工作。例如,我已将颜色更改为蓝色,这按预期工作。
\n\n有谁知道为什么它对转换不做同样的事情?
\n\n提前致谢!:)
\n\nvar btnE = document.querySelector(".btn-e");\r\n\r\nbtnE.addEventListener(\'mouseover\', function() {\r\n btnE.classList.add("btn-eScript")\r\n})\r\nbtnE.addEventListener("transitionend", function() {\r\n btnE.classList.remove("btn-eScript")\r\n})
Run Code Online (Sandbox Code Playgroud)\r\n.btn-e {\r\n margin-left: 155px;\r\n background-color: rgba(83, 155, 232, 0.9);\r\n}\r\n\r\n.btn-s {\r\n margin-left: 120px;\r\n background-color: rgb(236, 130, 139);\r\n}\r\n\r\n.btn-s,\r\n.btn-e {\r\n text-decoration: none;\r\n color: white;\r\n font-size: 90%;\r\n font-weight: 100;\r\n text-align: center;\r\n padding: 10px 20px;\r\n border-radius: 25px;\r\n transition: 0.15s;\r\n}\r\n\r\n.btn-eScript {\r\n color: blue;\r\n transform: scale(1.5);\r\n}
Run Code Online (Sandbox Code Playgroud)\r\n<div class="btns">\r\n <a class="btn-s" href="#">M\xc3\xa1s demos</a>\r\n <a class="btn-e" href="#">M\xc3\xa1s demos</a>\r\n</div>
Run Code Online (Sandbox Code Playgroud)\r\n