This repository has been archived by the owner on Dec 23, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
176 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2020 CleverGo. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
package clevergo | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
) | ||
|
||
// Error defines an HTTP response error. | ||
type Error interface { | ||
error | ||
Status() int | ||
} | ||
|
||
// Errors | ||
var ( | ||
ErrNotFound = StatusError{http.StatusNotFound, errors.New("404 page not found")} | ||
ErrMethodNotAllowed = StatusError{http.StatusMethodNotAllowed, errors.New(http.StatusText(http.StatusMethodNotAllowed))} | ||
) | ||
|
||
// ErrorHandler is a handler to handle error returns from handle. | ||
type ErrorHandler interface { | ||
Handle(ctx *Context, err error) | ||
} | ||
|
||
// StatusError implements Error interface. | ||
type StatusError struct { | ||
Code int | ||
Err error | ||
} | ||
|
||
// Error implements error.Error. | ||
func (se StatusError) Error() string { | ||
return se.Err.Error() | ||
} | ||
|
||
// Status implements Error.Status. | ||
func (se StatusError) Status() int { | ||
return se.Code | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.