mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 18:48:08 +00:00 
			
		
		
		
	 e768b73403
			
		
	
	e768b73403
	
	
	
		
			
			* Allow more complex errors from plugins This enables more complex types to be registered and returned from plugins. * Register common error types This is a slightly less drastic change, which keeps the HTTPCodedError as an interface. * Remove replication error from list
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package logical
 | |
| 
 | |
| type HTTPCodedError interface {
 | |
| 	Error() string
 | |
| 	Code() int
 | |
| }
 | |
| 
 | |
| func CodedError(status int, msg string) HTTPCodedError {
 | |
| 	return &codedError{
 | |
| 		Status:  status,
 | |
| 		Message: msg,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| type codedError struct {
 | |
| 	Status  int
 | |
| 	Message string
 | |
| }
 | |
| 
 | |
| func (e *codedError) Error() string {
 | |
| 	return e.Message
 | |
| }
 | |
| 
 | |
| func (e *codedError) Code() int {
 | |
| 	return e.Status
 | |
| }
 | |
| 
 | |
| // Struct to identify user input errors.  This is helpful in responding the
 | |
| // appropriate status codes to clients from the HTTP endpoints.
 | |
| type StatusBadRequest struct {
 | |
| 	Err string
 | |
| }
 | |
| 
 | |
| // Implementing error interface
 | |
| func (s *StatusBadRequest) Error() string {
 | |
| 	return s.Err
 | |
| }
 | |
| 
 | |
| // This is a new type declared to not cause potential compatibility problems if
 | |
| // the logic around the CodedError changes; in particular for logical request
 | |
| // paths it is basically ignored, and changing that behavior might cause
 | |
| // unforseen issues.
 | |
| type ReplicationCodedError struct {
 | |
| 	Msg  string
 | |
| 	Code int
 | |
| }
 | |
| 
 | |
| func (r *ReplicationCodedError) Error() string {
 | |
| 	return r.Msg
 | |
| }
 |