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

Handle REST status codes #74

Merged
merged 2 commits into from
May 2, 2024

Conversation

isinyaaa
Copy link
Contributor

Closes: opendatahub-io/model-registry-bf4-kf#305

Description

This handles REST status codes coming from the server core layer using enums and error unwrapping as introduced in GO 1.13.

How Has This Been Tested?

Tested with httpie and go tests.

Merge criteria:

  • The commits and have meaningful messages; the author will squash them after approval or will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@isinyaaa isinyaaa force-pushed the rest-status-codes branch 2 times, most recently from a5b2dfa to 04a55ec Compare April 29, 2024 21:40
Copy link
Member

@tarilabs tarilabs left a comment

Choose a reason for hiding this comment

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

Thank you @isinyaaa !

I prefer for this PR to consider changing return error codes also for failed conversions like s.converter ... in api_model_registry_service_service.go instead of 500 to return 400 for bad request, as discussed.

I'm not sure I understood internal/server/openapi/error.go modification, per comment below.

The mapping function, can be done in a subsequent PR.

internal/server/openapi/error.go Outdated Show resolved Hide resolved
Comment on lines +73 to +78
if errors.Is(err, api.ErrBadRequest) {
return Response(400, model.Error{Message: err.Error()}), nil
}
if errors.Is(err, api.ErrNotFound) {
return Response(404, model.Error{Message: err.Error()}), nil
}
Copy link
Member

Choose a reason for hiding this comment

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

eventually, there can be a mapping function as discussed which for known-errors will return a Response if mapped or nil, so we can refactor similar code here.

@isinyaaa isinyaaa force-pushed the rest-status-codes branch from 04a55ec to b89271c Compare April 30, 2024 14:07
Signed-off-by: Isabella do Amaral <idoamara@redhat.com>
Signed-off-by: Isabella do Amaral <idoamara@redhat.com>
@isinyaaa isinyaaa force-pushed the rest-status-codes branch from b89271c to ae57797 Compare April 30, 2024 16:01
@isinyaaa isinyaaa requested a review from tarilabs April 30, 2024 16:32
Copy link
Member

@tarilabs tarilabs left a comment

Choose a reason for hiding this comment

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

Thank you for incorporating required improvements and changes from #74 (review) @isinyaaa

/approve
/lgtm

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: isinyaaa, tarilabs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit ab5ffa9 into kubeflow:main May 2, 2024
10 checks passed
@isinyaaa isinyaaa deleted the rest-status-codes branch May 2, 2024 14:15
tarilabs added a commit to tarilabs/model-registry that referenced this pull request Jun 23, 2024
[pull] main from kubeflow:main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manage REST status codes
2 participants