Skip to content

feat(errors): add dedicated error type for blocked content #282

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

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
// ErrForbidden is returned when the client doesn't have permission to
// perform the requested operation.
ErrForbidden
ErrBlocked
)

func (e ErrorType) Error() string {
Expand All @@ -40,6 +41,8 @@ func (e ErrorType) String() string {
return "rate limited"
case ErrForbidden:
return "request forbidden"
case ErrBlocked:
return "content blocked"
default:
return "unknown error code"
}
Expand Down
2 changes: 2 additions & 0 deletions http/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ func parseResponse(httpRes *http.Response, req *cmds.Request) (cmds.Response, er
e.Code = cmds.ErrRateLimited
case http.StatusForbidden:
e.Code = cmds.ErrForbidden
case http.StatusGone, http.StatusUnavailableForLegalReasons:
e.Code = cmds.ErrBlocked
default:
e.Code = cmds.ErrNormal
}
Expand Down
5 changes: 4 additions & 1 deletion http/responseemitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@ func (re *responseEmitter) sendErr(err *cmds.Error) {

// Set the status from the error code.
status := http.StatusInternalServerError
if err.Code == cmds.ErrClient {
switch err.Code {
case cmds.ErrClient:
status = http.StatusBadRequest
case cmds.ErrBlocked:
status = http.StatusUnavailableForLegalReasons
}
re.w.WriteHeader(status)

Expand Down
Loading