mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: handle resource not found
This commit is contained in:
@@ -73,6 +73,9 @@ func (s *APIV2Service) GetResource(ctx context.Context, request *apiv2pb.GetReso
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to list resources: %v", err)
|
||||
}
|
||||
if resource == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "resource not found")
|
||||
}
|
||||
|
||||
return &apiv2pb.GetResourceResponse{
|
||||
Resource: s.convertResourceFromStore(ctx, resource),
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { useContext, useEffect } from "react";
|
||||
import useLoading from "@/hooks/useLoading";
|
||||
import { useMemoStore } from "@/store/v1";
|
||||
import MemoContent from "..";
|
||||
import { RendererContext } from "../types";
|
||||
@@ -11,17 +12,21 @@ interface Props {
|
||||
|
||||
const EmbeddedMemo = ({ memoId }: Props) => {
|
||||
const context = useContext(RendererContext);
|
||||
const loadingState = useLoading();
|
||||
const memoStore = useMemoStore();
|
||||
const memo = memoStore.getMemoById(memoId);
|
||||
const resourceName = `memos/${memoId}`;
|
||||
|
||||
useEffect(() => {
|
||||
memoStore.getOrFetchMemoById(memoId);
|
||||
memoStore.getOrFetchMemoById(memoId).finally(() => loadingState.setFinish());
|
||||
}, [memoId]);
|
||||
|
||||
if (!memo) {
|
||||
if (loadingState.isLoading) {
|
||||
return null;
|
||||
}
|
||||
if (!memo) {
|
||||
return <Error message={`Memo not found: ${memoId}`} />;
|
||||
}
|
||||
if (memoId === context.memoId || context.embeddedMemos.has(resourceName)) {
|
||||
return <Error message={`Nested Rendering Error: ![[${resourceName}]]`} />;
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import classNames from "classnames";
|
||||
import { useEffect } from "react";
|
||||
import MemoResourceListView from "@/components/MemoResourceListView";
|
||||
import useLoading from "@/hooks/useLoading";
|
||||
import { useResourceStore } from "@/store/v1";
|
||||
import Error from "./Error";
|
||||
|
||||
interface Props {
|
||||
resourceId: number;
|
||||
@@ -34,17 +36,21 @@ const getAdditionalClassNameWithParams = (params: URLSearchParams) => {
|
||||
};
|
||||
|
||||
const EmbeddedResource = ({ resourceId, params: paramsStr }: Props) => {
|
||||
const loadingState = useLoading();
|
||||
const resourceStore = useResourceStore();
|
||||
const resource = resourceStore.getResourceById(resourceId);
|
||||
const params = new URLSearchParams(paramsStr);
|
||||
|
||||
useEffect(() => {
|
||||
resourceStore.getOrFetchResourceById(resourceId);
|
||||
resourceStore.getOrFetchResourceById(resourceId).finally(() => loadingState.setFinish());
|
||||
}, [resourceId]);
|
||||
|
||||
if (!resource) {
|
||||
if (loadingState.isLoading) {
|
||||
return null;
|
||||
}
|
||||
if (!resource) {
|
||||
return <Error message={`Resource not found: ${resourceId}`} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={classNames("max-w-full", getAdditionalClassNameWithParams(params))}>
|
||||
|
Reference in New Issue
Block a user