Возвращаем ошибки по ссылке в реализациях репозиториев

This commit is contained in:
ErickSkrauch 2017-08-10 03:00:02 +03:00
parent 428bedf301
commit d9629b5e83
3 changed files with 8 additions and 9 deletions

View File

@ -15,13 +15,13 @@ type filesDb struct {
func (repository *filesDb) FindByUsername(username string) (model.Cape, error) {
var record model.Cape
if username == "" {
return record, CapeNotFoundError{username}
return record, &CapeNotFoundError{username}
}
capePath := path.Join(repository.path, strings.ToLower(username) + ".png")
file, err := os.Open(capePath)
if err != nil {
return record, CapeNotFoundError{username}
return record, &CapeNotFoundError{username}
}
record.File = file

View File

@ -19,13 +19,13 @@ const accountIdToUsernameKey string = "hash:username-to-account-id"
func (db *redisDb) FindByUsername(username string) (model.Skin, error) {
var record model.Skin
if username == "" {
return record, SkinNotFoundError{username}
return record, &SkinNotFoundError{username}
}
redisKey := buildKey(username)
response := db.conn.Cmd("GET", redisKey)
if response.IsType(redis.Nil) {
return record, SkinNotFoundError{username}
return record, &SkinNotFoundError{username}
}
encodedResult, err := response.Bytes()
@ -33,21 +33,19 @@ func (db *redisDb) FindByUsername(username string) (model.Skin, error) {
result, err := zlibDecode(encodedResult)
if err != nil {
log.Println("Cannot uncompress zlib for key " + redisKey)
goto finish
return record, err
}
err = json.Unmarshal(result, &record)
if err != nil {
log.Println("Cannot decode record data for key" + redisKey)
goto finish
return record, nil
}
record.OldUsername = record.Username
}
finish:
return record, err
return record, nil
}
func (db *redisDb) FindByUserId(id int) (model.Skin, error) {

View File

@ -61,6 +61,7 @@ func (s *uiService) Textures(response http.ResponseWriter, request *http.Request
cape, err := s.capesRepo.FindByUsername(username)
if err == nil {
// TODO: восстановить функционал получения ссылки на плащ
// capeUrl, err := services.Router.Get("cloaks").URL("username", username)
capeUrl := "/capes/" + username
if err != nil {