-
Notifications
You must be signed in to change notification settings - Fork 105
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
1 parent
4f9df7a
commit 5dc82f8
Showing
6 changed files
with
113 additions
and
37 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 |
---|---|---|
@@ -1,9 +1,67 @@ | ||
package models | ||
|
||
import "errors" | ||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
var ( | ||
// Config errors | ||
ErrMissingAllowedHosts error = errors.New("datasource is missing allowed hosts/URLs. Configure it in the datasource settings page for enhanced security") | ||
// Query errors | ||
ErrEmptyPaginationListFieldName error = &QueryValidationError{field: "pagination_param_list_field_name"} | ||
// Misc errors | ||
ErrUnsuccessfulHTTPResponseStatus error = errors.New("unsuccessful HTTP response") | ||
ErrParsingResponseBodyAsJson error = errors.New("unable to parse response body as JSON") | ||
ErrMissingAllowedHosts error = errors.New("datasource is missing allowed hosts/URLs. Configure it in the datasource settings page for enhanced security") | ||
) | ||
|
||
type ConfigValidationError struct { | ||
Field string | ||
} | ||
|
||
func (e *ConfigValidationError) Error() string { | ||
return fmt.Sprintf("invalid or empty field: %s ", e.Field) | ||
} | ||
|
||
type QueryValidationError struct { | ||
field string | ||
} | ||
|
||
func (e *QueryValidationError) Error() string { | ||
return fmt.Sprintf("invalid or empty field: %s ", e.field) | ||
} | ||
|
||
type macroError struct { | ||
message string | ||
secondaryMessage string | ||
macroName string | ||
field string | ||
} | ||
|
||
func (e *macroError) Error() string { | ||
if e.message == "invalid macro" { | ||
return fmt.Sprintf("invalid %s macro", e.macroName) | ||
} | ||
if e.macroName == "" { | ||
return e.message | ||
} | ||
if e.message == "" { | ||
return fmt.Sprintf("insufficient arguments to %s macro", e.macroName) | ||
} | ||
return fmt.Sprintf("error applying macros to %s field%s. %s", e.field, e.secondaryMessage, e.message) | ||
} | ||
|
||
type queryParsingError struct { | ||
message string | ||
err error | ||
} | ||
|
||
func (e *queryParsingError) Error() string { | ||
if e.err != nil && e.message == "" { | ||
return e.Error() | ||
} | ||
if e.err != nil { | ||
return fmt.Errorf("%s.%w", e.message, e.err).Error() | ||
} | ||
return e.message | ||
} |
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
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