Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.
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
2 changes: 1 addition & 1 deletion src/api/http-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { useMockedUrlFetchApp } from '~/api/test-helper'

test('HttpError', () => {
const res = useMockedUrlFetchApp(403, '{"message": "Forbidden"}')()
const error = new HttpError(res)
const error = new HttpError('https://example.com', res)
expect(error instanceof HttpError).toBeTruthy()
})
8 changes: 5 additions & 3 deletions src/api/http-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ export class HttpError implements Error {
public name = 'HttpError'
public message: string

// eslint-disable-next-line @typescript-eslint/camelcase
constructor(public response: GoogleAppsScript.URL_Fetch.HTTPResponse) {
this.message = `${response.getResponseCode()}: ${response.getContentText()}`
constructor(
public url: string,
public response: GoogleAppsScript.URL_Fetch.HTTPResponse // eslint-disable-line @typescript-eslint/camelcase
) {
this.message = `${url} - ${response.getResponseCode()}: ${response.getContentText()}`
}

public isInvalidTestingRequest(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/api/v2/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ test('HttpError#isInvalidTestingRequest', () => {
200,
'{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}'
)()
const error1 = new HttpError(res1)
const error1 = new HttpError('https://example.com', res1)
expect(error1.isInvalidTestingRequest()).toBeTruthy()

const res2 = useMockedUrlFetchApp(403, '{"message": "Forbidden"}')()
const error2 = new HttpError(res2)
const error2 = new HttpError('https://example.com', res2)
expect(error2.isInvalidTestingRequest()).toBeFalsy()
})

Expand Down
6 changes: 3 additions & 3 deletions src/api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class BuffettCodeApiClientV2 {

const code = res.getResponseCode()
const content = res.getContentText()
const error = new HttpError(res)
const error = new HttpError(url, res)
if (
Math.floor(code / 100) === 4 ||
Math.floor(code / 100) === 5 ||
Expand All @@ -29,8 +29,8 @@ export class BuffettCodeApiClientV2 {
try {
json = JSON.parse(content)
} catch (e) {
console.error('JSON parsing error', code, content)
throw new HttpError(res)
console.error('JSON parsing error', url, code, content)
throw new HttpError(url, res)
}

return json
Expand Down
4 changes: 2 additions & 2 deletions src/api/v3/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ describe('BuffettCodeApiClientV3', () => {
200,
'{"message":"Testing apikey is not allowed"}'
)()
const error1 = new HttpError(res1)
const error1 = new HttpError('https://example.com', res1)
expect(error1.isInvalidTestingRequest()).toBeTruthy()

const res2 = useMockedUrlFetchApp(403, '{"message": "Forbidden"}')()
const error2 = new HttpError(res2)
const error2 = new HttpError('https://example.com', res2)
expect(error2.isInvalidTestingRequest()).toBeFalsy()
})

Expand Down
6 changes: 3 additions & 3 deletions src/api/v3/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BuffettCodeApiClientV3 {

const code = res.getResponseCode()
const content = res.getContentText()
const error = new HttpError(res)
const error = new HttpError(url, res)
if (
Math.floor(code / 100) === 4 ||
Math.floor(code / 100) === 5 ||
Expand All @@ -34,8 +34,8 @@ export class BuffettCodeApiClientV3 {
try {
json = JSON.parse(content)
} catch (e) {
console.error('JSON parsing error', code, content)
throw new HttpError(res)
console.error('JSON parsing error', url, code, content)
throw new HttpError(url, res)
}

return json
Expand Down
4 changes: 2 additions & 2 deletions src/fiscal-periods/year-quarter-param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { YearQuarter } from '~/fiscal-periods/year-quarter'
export class YearQuarterParam {
constructor(public year: number | 'LY', public quarter: number | 'LQ') {
if (!this.isLatestYear() && year < 1) {
throw new InvalidYearError()
throw new InvalidYearError(`Invalid year value: ${year}`)
}

if (!this.isLatestQuarter() && (quarter < 1 || quarter > 4)) {
throw new InvalidQuarterError()
throw new InvalidQuarterError(`Invalid quarter value: ${quarter}`)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/fiscal-periods/year-quarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { InvalidYearError, InvalidQuarterError } from '~/fiscal-periods/error'
export class YearQuarter {
constructor(public year: number, public quarter: number) {
if (year < 1) {
throw new InvalidYearError()
throw new InvalidYearError(`Invalid year value: ${year}`)
}

if (quarter < 1 || quarter > 4) {
throw new InvalidQuarterError()
throw new InvalidQuarterError(`Invalid quarter value: ${quarter}`)
}
}

Expand Down