Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪟 🐛 Fix error message with missing docs #17071

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
};