Skip to content

Commit 9a3a1ce

Browse files
authored
Merge pull request #274 from samgozman/short-fork-2.0_fixes
Exceptions fixes
2 parents 260eee6 + eb81ad6 commit 9a3a1ce

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

backend/src/models/barchart/barchart.service.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export class BarchartService {
4040
.annual();
4141
barchartFinancialsIncome = await financials.income(stockTicker).annual();
4242
} catch (error) {
43-
console.error(error);
4443
return null;
4544
}
4645

@@ -70,12 +69,16 @@ export class BarchartService {
7069

7170
return {
7271
longTermDebt: longDebt ? [...longDebt].reverse() : null,
73-
shareholdersEquity: [
74-
...barchartFinancialsBalance.shareholdersEquity.total,
75-
].reverse(),
76-
netIncome: [...barchartFinancialsIncome.netIncome].reverse(),
77-
revenue: [...barchartFinancialsIncome.sales].reverse(),
78-
dates: [...dates].reverse(),
72+
shareholdersEquity: barchartFinancialsBalance.shareholdersEquity.total
73+
? [...barchartFinancialsBalance.shareholdersEquity.total].reverse()
74+
: [],
75+
netIncome: barchartFinancialsIncome.netIncome
76+
? [...barchartFinancialsIncome.netIncome].reverse()
77+
: [],
78+
revenue: barchartFinancialsIncome.sales
79+
? [...barchartFinancialsIncome.sales].reverse()
80+
: [],
81+
dates: dates ? [...dates].reverse() : [],
7982
};
8083
}
8184

@@ -84,7 +87,6 @@ export class BarchartService {
8487
try {
8588
barchartOverview = await quotes.overview(stockTicker);
8689
} catch (error) {
87-
console.error(error);
8890
return null;
8991
}
9092

backend/src/models/finviz/finviz.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ export class FinvizService {
6262
};
6363
return data;
6464
} catch (error) {
65-
// TODO: Log error to sentry, add exception filter
66-
console.error(error);
6765
return null;
6866
}
6967
}

backend/src/models/shortsqueeze/shortsqueeze.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ export class ShortsqueezeService {
1414
return this.squeezeRepository.set(stockTicker, data);
1515
}
1616

17-
async fetch(stockTicker: string): Promise<IShortsqueeze> {
17+
async fetch(stockTicker: string): Promise<IShortsqueeze | null> {
1818
const squeeze = await shortsqueeze(stockTicker);
19+
if (!squeeze) {
20+
return null;
21+
}
1922

2023
return {
2124
shortFlow: squeeze ? squeeze.shortPercentOfFloat : undefined,

backend/src/models/tightshorts/tightshorts.service.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Injectable } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33
import axios from 'axios';
4+
import type { AxiosRequestConfig } from 'axios';
45
import { TightshortsRepository } from './tightshorts.repository';
56
import type { ITightshorts } from './interfaces/tightshorts.interface';
67
import type { ITightshortsChart } from './interfaces/chart.interface';
@@ -20,8 +21,8 @@ export class TightshortsService {
2021
return this.tightshortsRepository.set(stockTicker, data);
2122
}
2223

23-
async fetch(stockTicker: string): Promise<ITightshorts> {
24-
const config = {
24+
async fetch(stockTicker: string): Promise<ITightshorts | null> {
25+
const config: AxiosRequestConfig<any> = {
2526
method: 'get',
2627
url: `${this.configService.get(
2728
'SHORT_API_URL',
@@ -30,9 +31,15 @@ export class TightshortsService {
3031
token: this.configService.get('SHORT_API_KEY'),
3132
'Content-Type': 'application/json',
3233
},
34+
validateStatus: (status) =>
35+
(status >= 200 && status < 300) || status === 404,
3336
};
3437

35-
const api = (await axios(config)).data;
38+
const response = await axios(config);
39+
if (response.status === 404) {
40+
return null;
41+
}
42+
const api = response.data;
3643

3744
const currentShortVolume =
3845
((api.volume[0].shortVolume / api.volume[0].totalVolume) * 100).toFixed(

0 commit comments

Comments
 (0)