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

[Aishwarya|Jenson] handle authorization error in schedule job #67

Merged
merged 1 commit into from
Jan 23, 2019
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
21 changes: 13 additions & 8 deletions daemon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func (c *client) ScheduleJob(name, tags, time, notificationEmails, group string,

defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
err := getHttpResponseError(resp.Body)
return "", err
return "", buildHTTPError(c, resp)
}

var scheduledJob ScheduleJobPayload
Expand Down Expand Up @@ -403,15 +402,21 @@ func buildHTTPError(c *client, resp *http.Response) error {
return fmt.Errorf("%s\n%s", utility.UnauthorizedErrorHeader, utility.UnauthorizedErrorMissingConfig)
}
return fmt.Errorf("%s\n%s", utility.UnauthorizedErrorHeader, utility.UnauthorizedErrorInvalidConfig)
} else if resp.StatusCode == http.StatusBadRequest {
}

if resp.StatusCode == http.StatusBadRequest {
return getHttpResponseError(resp.Body)
} else if resp.StatusCode == http.StatusNoContent {
}

if resp.StatusCode == http.StatusNoContent {
return fmt.Errorf(utility.NoScheduledJobsError)
} else if resp.StatusCode == http.StatusNotFound {
}

if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf(utility.JobNotFoundError)
} else {
return fmt.Errorf("%s\nStatus Code: %d, %s", utility.GenericResponseErrorHeader, resp.StatusCode, http.StatusText(resp.StatusCode))
}
}

return fmt.Errorf("%s\nStatus Code: %d, %s", utility.GenericResponseErrorHeader, resp.StatusCode, http.StatusText(resp.StatusCode))
}

func getHttpResponseError(response io_reader.ReadCloser) error {
Expand Down
4 changes: 2 additions & 2 deletions daemon/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (s *ClientTestSuite) TestSchedulingAlreadyExistedScheduledJob() {
"POST",
"http://"+proctorConfig.Host+"/jobs/schedule",
func(req *http.Request) (*http.Response, error) {
return httpmock.NewStringResponse(409, "provided duplicate combination of job name and args for scheduling"), nil
return httpmock.NewStringResponse(409, "Server Error!!!\nStatus Code: 409, Conflict"), nil
},
).WithHeader(
&http.Header{
Expand All @@ -371,7 +371,7 @@ func (s *ClientTestSuite) TestSchedulingAlreadyExistedScheduledJob() {
s.mockConfigLoader.On("Load").Return(proctorConfig, config.ConfigError{}).Once()

_, err := s.testClient.ScheduleJob(procName, tags, time, notificationEmails, group, procArgs)
assert.Equal(t, "provided duplicate combination of job name and args for scheduling", err.Error())
assert.Equal(t, "Server Error!!!\nStatus Code: 409, Conflict", err.Error())
s.mockConfigLoader.AssertExpectations(t)
}

Expand Down