Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Improve error handling#86

Merged
akiomik merged 1 commit intodevelopmentfrom
improve-error-handling
Jun 17, 2022
Merged

Improve error handling#86
akiomik merged 1 commit intodevelopmentfrom
improve-error-handling

Conversation

@akiomik
Copy link
Copy Markdown
Contributor

@akiomik akiomik commented Jun 17, 2022

エラーハンドリングの改善を行いました。

  • BCODE 関数とCSV出力のエラーハンドリングを共通化した ErrorHandler を追加
  • HttpError の改善
  • CSV出力のエラーハンドリングの改善

BCODE

スクリーンショット 2022-06-17 11 15 00

CSV

スクリーンショット 2022-06-17 11 53 54

@akiomik akiomik added the enhancement New feature or request label Jun 17, 2022
@akiomik akiomik requested a review from shoe116 June 17, 2022 03:10
@akiomik akiomik self-assigned this Jun 17, 2022
} else {
console.error('未定義のエラー', e.name, e.message)
throw new Error(
`<<未定義のエラーが発生しました (${e.name}: ${e.message})。改善しない場合はGoogleアカウントのログアウトおよび再ログインをお試しください>>`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

未定義のエラーが出た場合は再ログインを促すようにします。

range.setValues(data)
} catch (e) {
throw new Error(
`<<出力中にエラーが発生しました (${e.name}: ${e.message})。改善しない場合はGoogleアカウントのログアウトおよび再ログインをお試しください>>`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

シートに書き込むタイミングでエラーが出た場合は再ログインを促すようにします。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

完璧、本来出ないはずではあるが、出るからなこれ…

Comment on lines +33 to +38
let companyService
try {
companyService = new CompanyService(ticker, client, today)
} catch (e) {
ErrorHandler.handle(e)
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでエラーが出るとしたら HttpError だけの想定なんですが、どこでなんのエラーが出るかわからないので、未定義なエラーもハンドリングできるように ErrorHandler.handleHttpError ではなく広めに ErrorHandler.handle してます。

Comment on lines +59 to +68
try {
quarterApiPeriods.forEach(period => {
quarters.push(client.quarter(ticker, YearQuarterParam.fromYearQuarter(period)))
})
ondemandQuarterApiPeriods.forEach(period => {
quarters.push(client.ondemandQuarter(ticker, YearQuarterParam.fromYearQuarter(period)))
})
} catch (e) {
ErrorHandler.handle(e)
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上です。広めに ErrorHandler.handle してます。

import { ApiResponseError, OndemandApiNotEnabledError, UnsupportedTickerError } from '~/custom-functions/error'
import { InvalidLYLQError, InvalidYearError, InvalidQuarterError } from '~/fiscal-periods/error'

export class ErrorHandler {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

内部用の Error を受け取って外部向けの Error を投げ返すだけのクラスです。

@akiomik akiomik merged commit 9abe12f into development Jun 17, 2022
@akiomik akiomik deleted the improve-error-handling branch June 17, 2022 03:25
@akiomik akiomik mentioned this pull request Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants