mirror of
https://gitlab.com/RemixDev/deezer-js.git
synced 2025-01-14 10:35:16 +00:00
Moved all Error types in its own file
This commit is contained in:
parent
af1ee1d035
commit
15f475d321
|
@ -1,4 +1,15 @@
|
|||
const got = require('got')
|
||||
const {
|
||||
APIError,
|
||||
ItemsLimitExceededException,
|
||||
PermissionException,
|
||||
InvalidTokenException,
|
||||
WrongParameterException,
|
||||
MissingParameterException,
|
||||
InvalidQueryException,
|
||||
DataException,
|
||||
IndividualAccountChangedNotAllowedException
|
||||
} = require('./errors.js')
|
||||
|
||||
// Possible values for order parameter in search
|
||||
const SearchOrder = {
|
||||
|
@ -448,72 +459,7 @@ class API{
|
|||
}
|
||||
}
|
||||
|
||||
// Base class for Deezer exceptions
|
||||
class APIError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "APIError";
|
||||
}
|
||||
}
|
||||
class ItemsLimitExceededException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "ItemsLimitExceededException";
|
||||
}
|
||||
}
|
||||
class PermissionException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "PermissionException";
|
||||
}
|
||||
}
|
||||
class InvalidTokenException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "InvalidTokenException";
|
||||
}
|
||||
}
|
||||
class WrongParameterException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "WrongParameterException";
|
||||
}
|
||||
}
|
||||
class MissingParameterException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "MissingParameterException";
|
||||
}
|
||||
}
|
||||
class InvalidQueryException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "InvalidQueryException";
|
||||
}
|
||||
}
|
||||
class DataException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "DataException";
|
||||
}
|
||||
}
|
||||
class IndividualAccountChangedNotAllowedException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "IndividualAccountChangedNotAllowedException";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
SearchOrder,
|
||||
API,
|
||||
APIError,
|
||||
ItemsLimitExceededException,
|
||||
PermissionException,
|
||||
InvalidTokenException,
|
||||
WrongParameterException,
|
||||
MissingParameterException,
|
||||
InvalidQueryException,
|
||||
DataException,
|
||||
IndividualAccountChangedNotAllowedException
|
||||
API
|
||||
}
|
||||
|
|
102
deezer/errors.js
Normal file
102
deezer/errors.js
Normal file
|
@ -0,0 +1,102 @@
|
|||
class DeezerError extends Error {
|
||||
constructor(message) {
|
||||
super(message)
|
||||
this.name = "DeezerError"
|
||||
}
|
||||
}
|
||||
|
||||
class WrongLicense extends DeezerError {
|
||||
constructor(format) {
|
||||
super()
|
||||
this.name = "WrongLicense"
|
||||
this.message = `Your account can't request urls for ${format} tracks`
|
||||
this.format = format
|
||||
}
|
||||
}
|
||||
|
||||
class WrongGeolocation extends DeezerError {
|
||||
constructor(country) {
|
||||
super()
|
||||
this.name = "WrongGeolocation"
|
||||
this.message = `The track you requested can't be streamed in country ${country}`
|
||||
this.country = country
|
||||
}
|
||||
}
|
||||
|
||||
// APIError
|
||||
class APIError extends DeezerError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "APIError";
|
||||
}
|
||||
}
|
||||
class ItemsLimitExceededException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "ItemsLimitExceededException";
|
||||
}
|
||||
}
|
||||
class PermissionException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "PermissionException";
|
||||
}
|
||||
}
|
||||
class InvalidTokenException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "InvalidTokenException";
|
||||
}
|
||||
}
|
||||
class WrongParameterException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "WrongParameterException";
|
||||
}
|
||||
}
|
||||
class MissingParameterException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "MissingParameterException";
|
||||
}
|
||||
}
|
||||
class InvalidQueryException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "InvalidQueryException";
|
||||
}
|
||||
}
|
||||
class DataException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "DataException";
|
||||
}
|
||||
}
|
||||
class IndividualAccountChangedNotAllowedException extends APIError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "IndividualAccountChangedNotAllowedException";
|
||||
}
|
||||
}
|
||||
class GWAPIError extends DeezerError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "GWAPIError";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
DeezerError,
|
||||
WrongLicense,
|
||||
WrongGeolocation,
|
||||
APIError,
|
||||
ItemsLimitExceededException,
|
||||
PermissionException,
|
||||
InvalidTokenException,
|
||||
WrongParameterException,
|
||||
MissingParameterException,
|
||||
InvalidQueryException,
|
||||
DataException,
|
||||
IndividualAccountChangedNotAllowedException,
|
||||
GWAPIError
|
||||
}
|
12
deezer/gw.js
12
deezer/gw.js
|
@ -1,5 +1,6 @@
|
|||
const got = require('got')
|
||||
const {map_artist_album, map_user_track, map_user_artist, map_user_album, map_user_playlist} = require('./utils.js')
|
||||
const { GWAPIError } = require('./errors.js')
|
||||
|
||||
// Explicit Content Lyrics
|
||||
const LyricsStatus = {
|
||||
|
@ -436,18 +437,9 @@ class GW{
|
|||
|
||||
}
|
||||
|
||||
// Base class for Deezer exceptions
|
||||
class GWAPIError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "APIError";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
LyricsStatus,
|
||||
PlaylistStatus,
|
||||
EMPTY_TRACK_OBJ,
|
||||
GW,
|
||||
GWAPIError
|
||||
GW
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ const got = require('got')
|
|||
const {CookieJar, Cookie} = require('tough-cookie')
|
||||
const { API } = require('./api.js')
|
||||
const { GW } = require('./gw.js')
|
||||
const { DeezerError, WrongLicense, WrongGeolocation } = require('./errors.js')
|
||||
|
||||
// Number associtation for formats
|
||||
const TrackFormats = {
|
||||
|
@ -175,38 +176,11 @@ class Deezer{
|
|||
}
|
||||
}
|
||||
|
||||
class DeezerError extends Error {
|
||||
constructor() {
|
||||
super()
|
||||
this.name = "DeezerError"
|
||||
}
|
||||
}
|
||||
|
||||
class WrongLicense extends DeezerError {
|
||||
constructor(format) {
|
||||
super()
|
||||
this.name = "WrongLicense"
|
||||
this.message = `Your account can't request urls for ${format} tracks`
|
||||
}
|
||||
}
|
||||
|
||||
class WrongGeolocation extends DeezerError {
|
||||
constructor(country) {
|
||||
super()
|
||||
this.name = "WrongGeolocation"
|
||||
this.message = `The track you requested can't be streamed in country ${country}`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
TrackFormats,
|
||||
Deezer,
|
||||
api: {...require('./api.js')},
|
||||
gw: {...require('./gw.js')},
|
||||
utils: {...require('./utils.js')},
|
||||
errors: {
|
||||
DeezerError,
|
||||
WrongLicense,
|
||||
WrongGeolocation
|
||||
}
|
||||
errors: {...require('./errors.js')}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue