Skip to content

Commit

Permalink
setup sentry and eliminate typos
Browse files Browse the repository at this point in the history
  • Loading branch information
mvshmakov committed Jun 7, 2020
1 parent b8e8f14 commit 07da4fc
Show file tree
Hide file tree
Showing 22 changed files with 286 additions and 64 deletions.
125 changes: 125 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"test": "jest --config=configs/jest.json",
"test:watch": "jest --watch --coverage --config=configs/jest.json",
"test:coverage": "jest --coverage --config=configs/jest.json",
"type-check": "tsc --noEmit --pretty --incremental false --allowJs -t es5",
"type-check": "tsc --noEmit --pretty --esModuleInterop --incremental false --allowJs -t es5",
"type-check:watch": "npm run type-check -- --watch"
},
"husky": {
Expand All @@ -65,6 +65,7 @@
]
},
"dependencies": {
"@sentry/node": "^5.16.1",
"bot-metrica": "^1.0.2",
"commander": "^5.1.0",
"compression": "^1.7.4",
Expand Down
45 changes: 43 additions & 2 deletions src/api/v1/insomnia_api_v1.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"_type": "export",
"__export_format": 4,
"__export_date": "2020-06-03T13:43:19.531Z",
"__export_source": "insomnia.desktop.app:v7.1.1",
"__export_date": "2020-06-07T13:29:06.844Z",
"__export_source": "insomnia.desktop.app:v2020.2.1",
"resources": [
{
"_id": "req_50028f6275f4465ba2b088c89e306b41",
Expand Down Expand Up @@ -46,6 +46,7 @@
"modified": 1580210487023,
"name": "HSE Military bot",
"parentId": null,
"scope": null,
"_type": "workspace"
},
{
Expand Down Expand Up @@ -318,6 +319,36 @@
"url": "{{ apiProtocol }}://{{ apiHost }}:{{ apiPort }}/heapdump",
"_type": "request"
},
{
"_id": "req_86e8897ea9b74f15ae513872f972dd5b",
"authentication": {},
"body": {},
"created": 1591536388000,
"description": "",
"headers": [
{
"description": "",
"id": "pair_81a42afd36b24bcca7485a999a3eebc3",
"name": "authorization",
"value": "1"
}
],
"isPrivate": false,
"metaSortKey": -1587585947387,
"method": "GET",
"modified": 1591536521783,
"name": "/debugSentry",
"parameters": [],
"parentId": "fld_a5ade12af4ca495193e41e721ad84266",
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingFollowRedirects": "global",
"settingRebuildPath": true,
"settingSendCookies": true,
"settingStoreCookies": true,
"url": "{{ apiProtocol }}://{{ apiHost }}:{{ apiPort }}/debug-sentry",
"_type": "request"
},
{
"_id": "env_a9c203d564c42663231d117743280f52740012b9",
"color": null,
Expand All @@ -340,6 +371,16 @@
"parentId": "wrk_db648f62b3b24a2cac4541d49bf15b4a",
"_type": "cookie_jar"
},
{
"_id": "spc_de27f5fc37dd443b8b9ca9364b27f06c",
"contentType": "yaml",
"contents": "",
"created": 1591304851549,
"fileName": "HSE Military bot",
"modified": 1591304851549,
"parentId": "wrk_db648f62b3b24a2cac4541d49bf15b4a",
"_type": "api_spec"
},
{
"_id": "env_b06d5d5731144423a697e213c53bb82d",
"color": "#d70000",
Expand Down
4 changes: 0 additions & 4 deletions src/api/v1/routes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ commonRoutes.get("/", (_req: Request, res: Response) =>
),
);

commonRoutes.get("/ping", (_req: Request, res: Response) =>
res.status(200).send("ok"),
);

export default commonRoutes;
15 changes: 15 additions & 0 deletions src/api/v1/routes/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import { format } from "date-fns";
import { Router, Response, Request } from "express";

import Logger from "@/modules/Logger";
import BaseError from "@/modules/BaseError";

import { authMiddleware } from "../middlewares";

const SentryError = BaseError.createError("SentryError");

const debugRoutes = Router();

debugRoutes.get("/ping", (_req: Request, res: Response) =>
res.status(200).send("ok"),
);

debugRoutes.get("/heapdump", [
authMiddleware,
(_req: Request, res: Response): void => {
Expand All @@ -34,4 +42,11 @@ debugRoutes.get("/heapdump", [
},
]);

debugRoutes.get("/debugSentry", [
authMiddleware,
(): void => {
throw SentryError("Sentry error!");
},
]);

export default debugRoutes;
4 changes: 4 additions & 0 deletions src/bin/starter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { join } from "path";

import * as Sentry from "@sentry/node";
import * as dotenv from "dotenv";
import program from "commander";

import { resolveSentryConfigSync } from "@/resolvers/config";

import Bot from "@/modules/Bot";
import Server from "@/modules/Server";
import Logger from "@/modules/Logger";
Expand Down Expand Up @@ -33,6 +36,7 @@ const starter = async (): Promise<void> => {
});

Logger.info(`Starting ${mode} mode...`);
Sentry.init(resolveSentryConfigSync());

switch (mode) {
case "debug":
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { TReplyFunction } from "@/typings/custom";

const { inlineKeyboard, urlButton } = Markup;

const EnsureFromIdError = BaseError.createErrorGenerator("EnsureFromIdError");
const EnsureMessageError = BaseError.createErrorGenerator("EnsureMessageError");
const EnsureFromIdError = BaseError.createError("EnsureFromIdError");
const EnsureMessageError = BaseError.createError("EnsureMessageError");

export const ensureFromId = (
from: tt.User | undefined,
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ type TColumnDates = {

export const getAllCellsFromRow = (
worksheet: Worksheet,
rowIndeces: number[],
rowIndexes: number[],
startingColumn = 0,
): { row: number; dates: TColumnDates }[] => {
const arr: { row: number; dates: TColumnDates }[] = [];

rowIndeces.forEach((item) => {
rowIndexes.forEach((item) => {
const arrForEachRow: TColumnDates = [];

worksheet.getRow(item).eachCell((cell, colNumber) => {
Expand Down Expand Up @@ -62,7 +62,7 @@ export const getColorFromRowAndColumn = (
return undefined;
};

export const getAllActiveIndeces = (
export const getAllActiveIndexes = (
worksheet: Worksheet,
column: number,
trigger: string,
Expand Down Expand Up @@ -118,7 +118,7 @@ export const getTrainingsColorPalette = (
return colorPalette;
};

export const getColumnIndecesContainingString = (
export const getColumnIndexesContainingString = (
worksheet: Worksheet,
str: string,
): number[] => {
Expand All @@ -139,7 +139,7 @@ export const getColumnIndecesContainingString = (
return popSimilarValues(targetColumnNumber);
};

export const getRowIndecesContainingString = (
export const getRowIndexesContainingString = (
worksheet: Worksheet,
str: string,
): number[] => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/BaseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class BaseError extends Error {
}
}

static createErrorGenerator(name: string) {
static createError(name: string) {
return (message: string): BaseError => {
return new BaseError(name, message);
};
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Firebase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as firebase from "firebase-admin";
import BaseError from "@/modules/BaseError";
import { TFirebaseConfig } from "@/resolvers/config";

const FirebaseError = BaseError.createErrorGenerator("FirebaseInitError");
const FirebaseError = BaseError.createError("FirebaseInitError");

export default abstract class AbstractFirebase {
private _instance: firebase.database.Database;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Metrica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BaseError from "@/modules/BaseError";
import { resolveMetricaConfigSync } from "@/resolvers/config";

// TODO: all errors унести from classes
const MetricaInitError = BaseError.createErrorGenerator("MetricaInitError");
const MetricaInitError = BaseError.createError("MetricaInitError");

class Metrica {
private _instance: TMetricaTrackFunction;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/News.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { TArticle } from "google-news-rss";

import BaseError from "@/modules/BaseError";
// import resolveNewsArticles from "@/resolvers/news";
import { resolveNewsFileConfig } from "@/resolvers/config";
import { resolveNewsFileConfigSync } from "@/resolvers/config";

const NewsStorageError = BaseError.createErrorGenerator("NewsStorageError");
const NewsStorageError = BaseError.createError("NewsStorageError");

type TNewsObject = {
articles: TArticle[];
Expand All @@ -20,7 +20,7 @@ class NewsStorage {
}

async fromDumpOrBuild(): Promise<void> {
const { newsPath } = resolveNewsFileConfig();
const { newsPath } = resolveNewsFileConfigSync();

// Trying to restore existing parsed News from JSON on disk
if (existsSync(newsPath)) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Schedule/Downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Parser } from "htmlparser2";
import fetch from "node-fetch";
import BaseError from "@/modules//BaseError";

const ScheduleDownloaderError = BaseError.createErrorGenerator(
const ScheduleDownloaderError = BaseError.createError(
"ScheduleDownloaderError",
);

Expand Down

0 comments on commit 07da4fc

Please sign in to comment.