Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more error manager #64

Merged
merged 1 commit into from
Oct 14, 2023
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
4 changes: 4 additions & 0 deletions src/provider/github.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}

public async getRepoContent(route: string) {
const headers: HeadersInit = this.token ? { Authorization: `Bearer ${this.token}` } : {}

Check warning on line 61 in src/provider/github.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Object Literal Property name `Authorization` must match one of the following formats: camelCase

Check warning on line 61 in src/provider/github.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Object Literal Property name `Authorization` must match one of the following formats: camelCase
const response = await fetch(route, { headers })

if (response.status === 401) {
Expand All @@ -71,13 +71,17 @@
ErrorManager.outputError('Github API rate limit exceeded add token for higher limit')
return
}
if (response.status === 404) {
ErrorManager.outputError("Github repository not found (add token if it's private repository)")
return
}
return await response.json()
}

public async getFile(file: GithubResponse): Promise<Documentation> {
const data = await this.getRepoContent(file.url)
return {
type: this.fileSystem.getExtension(file.name)!,

Check warning on line 84 in src/provider/github.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Forbidden non-null assertion

Check warning on line 84 in src/provider/github.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Forbidden non-null assertion
name: file.name,
content: atob(data.content),
path: file.html_url,
Expand Down
9 changes: 6 additions & 3 deletions src/provider/gitlab.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@
}

public async getRepoContent(route: string) {
const headers: RequestInit = this.token ? { headers: { 'PRIVATE-TOKEN': this.token } } : {}

Check warning on line 57 in src/provider/gitlab.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Object Literal Property name `PRIVATE-TOKEN` must match one of the following formats: camelCase

Check warning on line 57 in src/provider/gitlab.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Object Literal Property name `PRIVATE-TOKEN` must match one of the following formats: camelCase
const response = await fetch(this.baseUrl + route, headers)

if (response.status === 401) {
ErrorManager.outputError(
"Gitlab Bad Credential: Votre token d'authentification est invalide ou expiré."
)
return
}
if (response.status === 403) {
ErrorManager.outputError('Gitlab API rate limit exceeded add token for higher limit')
return
}
if (response.status === 404) {
ErrorManager.outputError(
"Gitlab repository not found ( add token if it's private repository )"
)
ErrorManager.outputError("Gitlab repository not found (add token if it's private repository)")
return
}
return await response.json()
Expand All @@ -75,7 +78,7 @@
const filePathEncoded = encodeURIComponent(file.path)
const url = `https://gitlab.com/api/v4/projects/${this.repository.owner}%2F${this.repository.name}/repository/files/${filePathEncoded}/raw`
const requestOptions: RequestInit = this.token
? { headers: { 'PRIVATE-TOKEN': this.token } }

Check warning on line 81 in src/provider/gitlab.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Object Literal Property name `PRIVATE-TOKEN` must match one of the following formats: camelCase

Check warning on line 81 in src/provider/gitlab.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Object Literal Property name `PRIVATE-TOKEN` must match one of the following formats: camelCase
: {}

const response = await fetch(url, requestOptions)
Expand All @@ -87,7 +90,7 @@
}
const content = await response.text()
return {
type: this.fileSystem.getExtension(file.name)!,

Check warning on line 93 in src/provider/gitlab.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Forbidden non-null assertion

Check warning on line 93 in src/provider/gitlab.provider.ts

View workflow job for this annotation

GitHub Actions / Running tests...

Forbidden non-null assertion
name: file.name,
content: content,
path: `https://gitlab.com/${this.repository.owner}/${this.repository.name}/-/blob/main/${file.path}`,
Expand Down
Loading