Skip to content

Commit

Permalink
🪟 🐛 Fix error message with missing docs (#17071)
Browse files Browse the repository at this point in the history
* Fix error message with missing docs (#17014)

* Reverse type check logic
  • Loading branch information
timroes authored Sep 23, 2022
1 parent 4fe6a8b commit d4b7f4e
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/html")) {
throw new Error(`Documentation was text/html and such ignored since markdown couldn't be found.`);
}

return await response.text();
};

0 comments on commit d4b7f4e

Please sign in to comment.