PageRenderTime 26ms CodeModel.GetById 2ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/spotify/error.go

https://github.com/tomnewton/go-libspotify
Go | 145 lines | 49 code | 40 blank | 56 comment | 2 complexity | df3635a3827a174c7fd2d72cacecbee1 MD5 | raw file
  1// Copyright 2013 Örjan Persson
  2//
  3// Licensed under the Apache License, Version 2.0 (the "License");
  4// you may not use this file except in compliance with the License.
  5// You may obtain a copy of the License at
  6//
  7//     http://www.apache.org/licenses/LICENSE-2.0
  8//
  9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15package spotify
 16
 17/*
 18#cgo pkg-config: libspotify
 19#include <libspotify/api.h>
 20*/
 21import "C"
 22
 23type Error C.sp_error
 24
 25func (e Error) Error() string {
 26	return C.GoString(C.sp_error_message(C.sp_error(e)))
 27}
 28
 29const (
 30	// The library version targeted does not match the one you claim you
 31	// support
 32	ErrBadAPIVersion Error = Error(C.SP_ERROR_BAD_API_VERSION)
 33
 34	// Initialization of library failed - are cache locations etc. valid?
 35	ErrAPIInitializationFailed = Error(C.SP_ERROR_API_INITIALIZATION_FAILED)
 36
 37	// The track specified for playing cannot be played
 38	ErrTrackNotPlayable = Error(C.SP_ERROR_TRACK_NOT_PLAYABLE)
 39
 40	// The application key is invalid
 41	ErrBadApplicationKey = Error(C.SP_ERROR_BAD_APPLICATION_KEY)
 42
 43	// Login failed because of bad username and/or password
 44	ErrBadUsernameOrPassword = Error(C.SP_ERROR_BAD_USERNAME_OR_PASSWORD)
 45
 46	// The specified username is banned
 47	ErrUserBanned = Error(C.SP_ERROR_USER_BANNED)
 48
 49	// Cannot connect to the Spotify backend system
 50	ErrUnableToContactServer = Error(C.SP_ERROR_UNABLE_TO_CONTACT_SERVER)
 51
 52	// Client is too old, library will need to be updated
 53	ErrClientTooOld = Error(C.SP_ERROR_CLIENT_TOO_OLD)
 54
 55	// Some other error occurred, and it is permanent (e.g. trying to relogin
 56	// will not help)
 57	ErrOtherPermanent = Error(C.SP_ERROR_OTHER_PERMANENT)
 58
 59	// The user agent string is invalid or too long
 60	ErrBadUserAgent = Error(C.SP_ERROR_BAD_USER_AGENT)
 61
 62	// No valid callback registered to handle events
 63	ErrMissingCallback = Error(C.SP_ERROR_MISSING_CALLBACK)
 64
 65	// Input data was either missing or invalid
 66	ErrInvalidIndata = Error(C.SP_ERROR_INVALID_INDATA)
 67
 68	// Index out of range
 69	ErrIndexOutOfRange = Error(C.SP_ERROR_INDEX_OUT_OF_RANGE)
 70
 71	// The specified user needs a premium account
 72	ErrUserNeedsPremium = Error(C.SP_ERROR_USER_NEEDS_PREMIUM)
 73
 74	// A transient error occurred.
 75	ErrOtherTransient = Error(C.SP_ERROR_OTHER_TRANSIENT)
 76
 77	// The resource is currently loading
 78	ErrIsLoading = Error(C.SP_ERROR_IS_LOADING)
 79
 80	// Could not find any suitable stream to play
 81	ErrNoStreamAvailable = Error(C.SP_ERROR_NO_STREAM_AVAILABLE)
 82
 83	// Requested operation is not allowed
 84	ErrPermissionDenied = Error(C.SP_ERROR_PERMISSION_DENIED)
 85
 86	// Target inbox is full
 87	ErrInboxIsFull = Error(C.SP_ERROR_INBOX_IS_FULL)
 88
 89	// Cache is not enabled
 90	ErrNoCache = Error(C.SP_ERROR_NO_CACHE)
 91
 92	// Requested user does not exist
 93	ErrNoSuchUser = Error(C.SP_ERROR_NO_SUCH_USER)
 94
 95	// No credentials are stored
 96	ErrNoCredentials = Error(C.SP_ERROR_NO_CREDENTIALS)
 97
 98	// Network disabled
 99	ErrNetworkDisabled = Error(C.SP_ERROR_NETWORK_DISABLED)
100
101	// Invalid device ID
102	ErrInvalidDeviceId = Error(C.SP_ERROR_INVALID_DEVICE_ID)
103
104	// Unable to open trace file
105	ErrCantOpenTraceFile = Error(C.SP_ERROR_CANT_OPEN_TRACE_FILE)
106
107	// This application is no longer allowed to use the Spotify service
108	ErrApplicationBanned = Error(C.SP_ERROR_APPLICATION_BANNED)
109
110	// Reached the device limit for number of tracks to download
111	ErrOfflineTooManyTracks = Error(C.SP_ERROR_OFFLINE_TOO_MANY_TRACKS)
112
113	// Disk cache is full so no more tracks can be downloaded to offline mode
114	ErrOfflineDiskCache = Error(C.SP_ERROR_OFFLINE_DISK_CACHE)
115
116	// Offline key has expired, the user needs to go online again
117	ErrOfflineExpired = Error(C.SP_ERROR_OFFLINE_EXPIRED)
118
119	// This user is not allowed to use offline mode
120	ErrOfflineNotAllowed = Error(C.SP_ERROR_OFFLINE_NOT_ALLOWED)
121
122	// The license for this device has been lost. Most likely because the user
123	// used offline on three other device
124	ErrOfflineLicenseLost = Error(C.SP_ERROR_OFFLINE_LICENSE_LOST)
125
126	// The Spotify license server does not respond correctly
127	ErrOfflineLicenseError = Error(C.SP_ERROR_OFFLINE_LICENSE_ERROR)
128
129	// A LastFM scrobble authentication error has occurred
130	ErrLastFMAuthError = Error(C.SP_ERROR_LASTFM_AUTH_ERROR)
131
132	// An invalid argument was specified
133	ErrInvalidArgument = Error(C.SP_ERROR_INVALID_ARGUMENT)
134
135	// An operating system error
136	ErrSystemFailure = Error(C.SP_ERROR_SYSTEM_FAILURE)
137)
138
139// spError converts an error from libspotify into a Go error.
140func spError(err C.sp_error) error {
141	if err != C.SP_ERROR_OK {
142		return Error(err)
143	}
144	return nil
145}