Skip to content

Commit

Permalink
(Re-)Add client-side logging (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrsmutti authored Feb 19, 2020
1 parent bd55613 commit 77228a8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Client-side logging.

## [0.6.15] - 2020-02-14

### Added
Expand Down
7 changes: 7 additions & 0 deletions react/components/SearchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { useState } from "react";
import { useQuery } from "react-apollo";
import PropTypes from "prop-types";
import { path, pathOr, isEmpty, reject } from "ramda";
import { useRuntime } from "vtex.render-runtime";
import { onSearchResult } from "vtex.sae-analytics";
import BiggyClient from "../utils/biggy-client.ts";
import {
makeFetchMore,
fromAttributesToFacets,
} from "../utils/compatibility-layer.ts";
import logError from "../utils/log";

import searchResultQuery from "../graphql/searchResult.gql";

Expand All @@ -23,6 +25,7 @@ const SearchQuery = ({
variables,
order,
}) => {
const { account, workspace } = useRuntime();
const [page, setPage] = useState(1);

const searchResult = useQuery(searchResultQuery, {
Expand All @@ -35,6 +38,10 @@ const SearchQuery = ({
},
});

if (searchResult.error) {
logError(account, workspace, attributePath, searchResult.error);
}

const redirect = path(["data", "searchResult", "redirect"], searchResult);
searchResult.loading = searchResult.loading || redirect;

Expand Down
31 changes: 31 additions & 0 deletions react/utils/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import axios from "axios";

const client = axios.create({
baseURL: "https://search.biggylabs.com.br/search-api/v1",
headers: {
"Content-Type": "application/json",
},
});

const logError = (
store: string,
workspace: string,
attributePath: string,
error: any,
) => {
const browser =
typeof navigator !== "undefined"
? navigator.userAgent
: "server-side-error";

const message = `Workspace: ${workspace}\nBrowser: ${browser}\nMessage: ${
error.message
}\n${error.stack != null ? error.stack : ""}`;

client.post(`/${store}/log`, {
message,
url: `Search App Error at: ${attributePath}`,
});
};

export default logError;

0 comments on commit 77228a8

Please sign in to comment.