fix(github): prevent panic when no response is available
This commit is contained in:
parent
84087ffa62
commit
4d6459fae5
@ -29,9 +29,13 @@ func (f *Forge) CreateIssue(ctx context.Context, projectID string, title string,
|
|||||||
Title: &title,
|
Title: &title,
|
||||||
Body: &body,
|
Body: &body,
|
||||||
})
|
})
|
||||||
if res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized {
|
if err != nil {
|
||||||
slog.ErrorContext(ctx, "could not create issue", slog.Any("error", errors.WithStack(err)))
|
if res != nil && (res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized) {
|
||||||
return "", errors.WithStack(service.ErrForgeNotAvailable)
|
slog.ErrorContext(ctx, "could not create issue", slog.Any("error", errors.WithStack(err)))
|
||||||
|
return "", errors.WithStack(service.ErrForgeNotAvailable)
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return *issue.HTMLURL, nil
|
return *issue.HTMLURL, nil
|
||||||
@ -51,7 +55,7 @@ func (f *Forge) GetAllProjects(ctx context.Context) ([]*model.Project, error) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized {
|
if res != nil && (res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized) {
|
||||||
slog.ErrorContext(ctx, "could not retrieve user repositories", slog.Any("error", errors.WithStack(err)))
|
slog.ErrorContext(ctx, "could not retrieve user repositories", slog.Any("error", errors.WithStack(err)))
|
||||||
return nil, errors.WithStack(service.ErrForgeNotAvailable)
|
return nil, errors.WithStack(service.ErrForgeNotAvailable)
|
||||||
}
|
}
|
||||||
@ -94,7 +98,7 @@ func (f *Forge) GetFile(ctx context.Context, rawProjectID string, path string) (
|
|||||||
|
|
||||||
fileContent, _, res, err := f.client.Repositories.GetContents(ctx, *repo.Owner.Login, *repo.Name, path, nil)
|
fileContent, _, res, err := f.client.Repositories.GetContents(ctx, *repo.Owner.Login, *repo.Name, path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized {
|
if res != nil && (res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized) {
|
||||||
slog.ErrorContext(ctx, "could not retrieve file content", slog.Any("error", errors.WithStack(err)))
|
slog.ErrorContext(ctx, "could not retrieve file content", slog.Any("error", errors.WithStack(err)))
|
||||||
return nil, errors.WithStack(service.ErrForgeNotAvailable)
|
return nil, errors.WithStack(service.ErrForgeNotAvailable)
|
||||||
}
|
}
|
||||||
@ -185,7 +189,7 @@ func (f *Forge) GetProjectLanguages(ctx context.Context, rawProjectID string) ([
|
|||||||
|
|
||||||
mappedLanguages, res, err := f.client.Repositories.ListLanguages(ctx, *repo.Owner.Login, *repo.Name)
|
mappedLanguages, res, err := f.client.Repositories.ListLanguages(ctx, *repo.Owner.Login, *repo.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized {
|
if res != nil && (res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized) {
|
||||||
slog.ErrorContext(ctx, "could not retrieve repository languages", slog.Any("error", errors.WithStack(err)))
|
slog.ErrorContext(ctx, "could not retrieve repository languages", slog.Any("error", errors.WithStack(err)))
|
||||||
return nil, errors.WithStack(service.ErrForgeNotAvailable)
|
return nil, errors.WithStack(service.ErrForgeNotAvailable)
|
||||||
}
|
}
|
||||||
@ -210,7 +214,7 @@ func (f *Forge) getRepository(ctx context.Context, rawProjectID string) (*github
|
|||||||
|
|
||||||
repo, res, err := f.client.Repositories.GetByID(ctx, projectID)
|
repo, res, err := f.client.Repositories.GetByID(ctx, projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized {
|
if res != nil && (res.StatusCode == http.StatusForbidden || res.StatusCode == http.StatusUnauthorized) {
|
||||||
slog.ErrorContext(ctx, "could not retrieve repository", slog.Any("error", errors.WithStack(err)))
|
slog.ErrorContext(ctx, "could not retrieve repository", slog.Any("error", errors.WithStack(err)))
|
||||||
return nil, errors.WithStack(service.ErrForgeNotAvailable)
|
return nil, errors.WithStack(service.ErrForgeNotAvailable)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user