Skip to content

Commit

Permalink
Fix error message with missing docs (#17014)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes committed Sep 22, 2022
1 parent 0ceffd7 commit e931b69
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const DocumentationPanel: React.FC = () => {
const { formatMessage } = useIntl();
const config = useConfig();
const { setDocumentationPanelOpen, documentationUrl } = useDocumentationPanelContext();
const { data: docs, isLoading } = useDocumentation(documentationUrl);
const { data: docs, isLoading, error } = useDocumentation(documentationUrl);

// @ts-expect-error rehype-slug currently has type conflicts due to duplicate vfile dependencies
const urlReplacerPlugin: PluggableList = useMemo<PluggableList>(() => {
Expand Down Expand Up @@ -55,7 +55,7 @@ export const DocumentationPanel: React.FC = () => {
<PageTitle withLine title={<FormattedMessage id="connector.setupGuide" />} />
<Markdown
className={styles.content}
content={!docs?.includes("<!DOCTYPE html>") ? docs : formatMessage({ id: "connector.setupGuide.notFound" })}
content={docs && !error ? docs : formatMessage({ id: "connector.setupGuide.notFound" })}
rehypePlugins={urlReplacerPlugin}
/>
</div>
Expand Down
14 changes: 14 additions & 0 deletions airbyte-webapp/src/core/domain/Documentation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fetchDocumentation } from "./Documentation";

describe("fetchDocumentation", () => {
afterEach(() => {
jest.resetAllMocks();
});

it("should throw on non markdown content-type", async () => {
global.fetch = jest.fn().mockResolvedValue({
Headers: new Headers([["Content-Type", "text/html; charset=utf-8"]]),
});
await expect(fetchDocumentation("/docs/integrations/destinations/firestore.md")).rejects.toThrow();
});
});
6 changes: 6 additions & 0 deletions airbyte-webapp/src/core/domain/Documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ export const fetchDocumentation = async (url: string): Promise<string> => {
method: "GET",
});

const contentType = response.headers.get("content-type");

if (!contentType?.toLowerCase().includes("text/markdown")) {
throw new Error(`Documentation to be expected text/markdown, was ${contentType}`);
}

return await response.text();
};

0 comments on commit e931b69

Please sign in to comment.