-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add more specific api error handling
- Loading branch information
1 parent
fabbe31
commit 44191ac
Showing
10 changed files
with
135 additions
and
70 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,34 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/wundergraph/cosmo/connect-go/gen/proto/wg/cosmo/common" | ||
) | ||
|
||
var ( | ||
ErrEmptyMsg = fmt.Errorf("empty message") | ||
ErrNotFound = fmt.Errorf("resource not found") | ||
ErrSubgraphCompositionFailed = fmt.Errorf("subgraph composition failed") | ||
) | ||
|
||
func IsNotFoundError(err error) bool { | ||
return err == ErrNotFound | ||
} | ||
|
||
func IsSubgraphCompositionFailedError(err error) bool { | ||
return err == ErrSubgraphCompositionFailed | ||
} | ||
|
||
func handleErrorCodes(statusCode common.EnumStatusCode) error { | ||
switch statusCode { | ||
case common.EnumStatusCode_OK: | ||
return nil | ||
case common.EnumStatusCode_ERR_SUBGRAPH_COMPOSITION_FAILED: | ||
return ErrSubgraphCompositionFailed | ||
case common.EnumStatusCode_ERR_NOT_FOUND: | ||
return ErrNotFound | ||
default: | ||
return fmt.Errorf("failed to create resource: %s", statusCode.String()) | ||
} | ||
} |
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
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.