From 6783d82bf298a68bfca79f1a3b7b39b59ab9ad91 Mon Sep 17 00:00:00 2001 From: atridadl Date: Wed, 24 Jan 2024 22:33:58 -0700 Subject: [PATCH] Better error handling --- lib/replicate.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/replicate.go b/lib/replicate.go index cce3089..d69404c 100644 --- a/lib/replicate.go +++ b/lib/replicate.go @@ -33,10 +33,14 @@ func ReplicateTextGeneration(prompt string) (string, error) { return "", predictionError } + if prediction == nil { + return "", errors.New("there was an error generating a response based on this prompt... please reach out to @himbothyswaggins to fix this issue") + } + test, ok := prediction.([]interface{}) if !ok { - return "", errors.New("there was an error generating the image based on this prompt... this usually happens when the generated image violates safety requirements") + return "", errors.New("there was an error generating a response based on this prompt... please reach out to @himbothyswaggins to fix this issue") } strs := make([]string, len(test)) @@ -76,16 +80,20 @@ func ReplicateImageGeneration(prompt string, filename string) (*bytes.Buffer, er return nil, predictionError } + if prediction == nil { + return nil, errors.New("there was an error generating the image based on this prompt... please reach out to @himbothyswaggins to fix this issue") + } + test, ok := prediction.([]interface{}) if !ok { - return nil, errors.New("there was an error generating the image based on this prompt... this usually happens when the generated image violates safety requirements") + return nil, errors.New("there was an error generating the image based on this prompt... please reach out to @himbothyswaggins to fix this issue") } imgUrl, ok := test[0].(string) if !ok { - return nil, errors.New("there was an error generating the image based on this prompt... this usually happens when the generated image violates safety requirements") + return nil, errors.New("there was an error generating the image based on this prompt... please reach out to @himbothyswaggins to fix this issue") } imageRes, imageGetErr := http.Get(imgUrl)