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 {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "failed to list resources: %v", err)
|
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{
|
return &apiv2pb.GetResourceResponse{
|
||||||
Resource: s.convertResourceFromStore(ctx, resource),
|
Resource: s.convertResourceFromStore(ctx, resource),
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { useContext, useEffect } from "react";
|
import { useContext, useEffect } from "react";
|
||||||
|
import useLoading from "@/hooks/useLoading";
|
||||||
import { useMemoStore } from "@/store/v1";
|
import { useMemoStore } from "@/store/v1";
|
||||||
import MemoContent from "..";
|
import MemoContent from "..";
|
||||||
import { RendererContext } from "../types";
|
import { RendererContext } from "../types";
|
||||||
@@ -11,17 +12,21 @@ interface Props {
|
|||||||
|
|
||||||
const EmbeddedMemo = ({ memoId }: Props) => {
|
const EmbeddedMemo = ({ memoId }: Props) => {
|
||||||
const context = useContext(RendererContext);
|
const context = useContext(RendererContext);
|
||||||
|
const loadingState = useLoading();
|
||||||
const memoStore = useMemoStore();
|
const memoStore = useMemoStore();
|
||||||
const memo = memoStore.getMemoById(memoId);
|
const memo = memoStore.getMemoById(memoId);
|
||||||
const resourceName = `memos/${memoId}`;
|
const resourceName = `memos/${memoId}`;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
memoStore.getOrFetchMemoById(memoId);
|
memoStore.getOrFetchMemoById(memoId).finally(() => loadingState.setFinish());
|
||||||
}, [memoId]);
|
}, [memoId]);
|
||||||
|
|
||||||
if (!memo) {
|
if (loadingState.isLoading) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!memo) {
|
||||||
|
return <Error message={`Memo not found: ${memoId}`} />;
|
||||||
|
}
|
||||||
if (memoId === context.memoId || context.embeddedMemos.has(resourceName)) {
|
if (memoId === context.memoId || context.embeddedMemos.has(resourceName)) {
|
||||||
return <Error message={`Nested Rendering Error: ![[${resourceName}]]`} />;
|
return <Error message={`Nested Rendering Error: ![[${resourceName}]]`} />;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import MemoResourceListView from "@/components/MemoResourceListView";
|
import MemoResourceListView from "@/components/MemoResourceListView";
|
||||||
|
import useLoading from "@/hooks/useLoading";
|
||||||
import { useResourceStore } from "@/store/v1";
|
import { useResourceStore } from "@/store/v1";
|
||||||
|
import Error from "./Error";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
resourceId: number;
|
resourceId: number;
|
||||||
@@ -34,17 +36,21 @@ const getAdditionalClassNameWithParams = (params: URLSearchParams) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const EmbeddedResource = ({ resourceId, params: paramsStr }: Props) => {
|
const EmbeddedResource = ({ resourceId, params: paramsStr }: Props) => {
|
||||||
|
const loadingState = useLoading();
|
||||||
const resourceStore = useResourceStore();
|
const resourceStore = useResourceStore();
|
||||||
const resource = resourceStore.getResourceById(resourceId);
|
const resource = resourceStore.getResourceById(resourceId);
|
||||||
const params = new URLSearchParams(paramsStr);
|
const params = new URLSearchParams(paramsStr);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resourceStore.getOrFetchResourceById(resourceId);
|
resourceStore.getOrFetchResourceById(resourceId).finally(() => loadingState.setFinish());
|
||||||
}, [resourceId]);
|
}, [resourceId]);
|
||||||
|
|
||||||
if (!resource) {
|
if (loadingState.isLoading) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!resource) {
|
||||||
|
return <Error message={`Resource not found: ${resourceId}`} />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames("max-w-full", getAdditionalClassNameWithParams(params))}>
|
<div className={classNames("max-w-full", getAdditionalClassNameWithParams(params))}>
|
||||||
|
Reference in New Issue
Block a user