glusterd2 icon indicating copy to clipboard operation
glusterd2 copied to clipboard

API Custom error codes

Open aravindavk opened this issue 5 years ago • 10 comments

REST API status code can be used to identify the request is failed or not. Granular error code should be available in error response.

General HTTP status codes

  • Success: 200, 201, 204
  • Resource not found: 404
  • Invalid input/Bad request: 400
  • Conflict/Busy: 409
  • API error from server: 500

Custom error codes are required for the following(incomplete list, need to identify other failure scenarios)

  • Peer add:
    • Peer already Exists
  • Peer Remove
    • Peer not found(HTTP status 404)
  • Volume Create
    • Volume already exists
  • Volume Start
    • Volume not found
    • Volume already started
  • Volume Stop
    • Volume not found
    • Volume already stopped
  • Volume Delete
    • Volume not found

aravindavk avatar Aug 06 '18 05:08 aravindavk

@sac @prashanthpai @kshlm @Madhu-1 please add if any other error codes are required.

aravindavk avatar Aug 06 '18 05:08 aravindavk

http.StatusUnauthorized http.StatusUnprocessableEntity

Madhu-1 avatar Aug 06 '18 05:08 Madhu-1

http.StatusUnprocessableEntity is hard to get right - it's debatable what it means. We removed it a while ago. I'd simply use 400 instead.

I want StatusUnprocessableEntity to mean that JSON parsing failed but that's not what it's intended for: https://httpstatuses.com/422

prashanthpai avatar Aug 06 '18 05:08 prashanthpai

@prashanthpai AFAIK we are using http.StatusUnprocessableEntity in gd2

./glusterd2/commands/snapshot/snapshot-create.go:		restutils.SendHTTPError(ctx, w, http.StatusUnprocessableEntity, gderrors.ErrInvalidSnapName)
./glusterd2/commands/snapshot/snapshot-activate.go:		restutils.SendHTTPError(ctx, w, http.StatusUnprocessableEntity, err)
./glusterd2/commands/snapshot/snapshot-clone.go:		restutils.SendHTTPError(ctx, w, http.StatusUnprocessableEntity, errors.New("Snapshot name should not be empty"))
./glusterd2/commands/snapshot/snapshot-clone.go:		restutils.SendHTTPError(ctx, w, http.StatusUnprocessableEntity, gderrors.ErrInvalidVolName)

Madhu-1 avatar Aug 06 '18 05:08 Madhu-1

@Madhu-1 Those needs to be changed

prashanthpai avatar Aug 06 '18 05:08 prashanthpai

See https://github.com/gluster/glusterd2/issues/611

prashanthpai avatar Aug 06 '18 05:08 prashanthpai

@prashanthpai agreed.

Madhu-1 avatar Aug 06 '18 05:08 Madhu-1

@aravindavk looks okay to me. I'll check the library once and get back to this.

sac avatar Aug 06 '18 06:08 sac

@Madhu-1 What more work is pending here?

atinmu avatar Nov 30 '18 11:11 atinmu

Not a blocker for GCS/1.0 from the revised MVP perspective.

atinmu avatar Jan 17 '19 11:01 atinmu