Commit f66c7500 authored by Johnny's avatar Johnny

chore: simplify attachment file writing

parent bd02de98
......@@ -90,11 +90,12 @@ func (p *IdentityProvider) UserInfo(token string) (*idp.IdentityProviderUserInfo
if err != nil {
return nil, errors.Wrap(err, "failed to get user information")
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrap(err, "failed to read response body")
}
defer resp.Body.Close()
var claims map[string]any
if err := json.Unmarshal(body, &claims); err != nil {
......
......@@ -153,9 +153,11 @@ func (s *Scheduler) runJobWithSchedule(ctx context.Context, rj *registeredJob, s
_ = err
}
case <-ctx.Done():
// Stop the timer to prevent it from firing. The timer will be garbage collected.
timer.Stop()
return
case <-s.stopCh:
// Stop the timer to prevent it from firing. The timer will be garbage collected.
timer.Stop()
return
}
......
......@@ -49,12 +49,12 @@ func Post(requestPayload *WebhookRequestPayload) error {
if err != nil {
return errors.Wrapf(err, "failed to post webhook to %s", requestPayload.URL)
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return errors.Wrapf(err, "failed to read webhook response from %s", requestPayload.URL)
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return errors.Errorf("failed to post webhook %s, status code: %d, response body: %s", requestPayload.URL, resp.StatusCode, b)
......
......@@ -317,11 +317,6 @@ func SaveAttachmentBlob(ctx context.Context, profile *profile.Profile, stores *s
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
return errors.Wrap(err, "Failed to create directory")
}
dst, err := os.Create(osPath)
if err != nil {
return errors.Wrap(err, "Failed to create file")
}
defer dst.Close()
// Write the blob to the file.
if err := os.WriteFile(osPath, create.Blob, 0644); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment