Moved all Error types in its own file

This commit is contained in:
RemixDev 2021-08-02 20:38:50 +02:00
parent af1ee1d035
commit 15f475d321
4 changed files with 118 additions and 104 deletions

View file

@ -1,4 +1,15 @@
const got = require('got') const got = require('got')
const {
APIError,
ItemsLimitExceededException,
PermissionException,
InvalidTokenException,
WrongParameterException,
MissingParameterException,
InvalidQueryException,
DataException,
IndividualAccountChangedNotAllowedException
} = require('./errors.js')
// Possible values for order parameter in search // Possible values for order parameter in search
const SearchOrder = { 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 = { module.exports = {
SearchOrder, SearchOrder,
API, API
APIError,
ItemsLimitExceededException,
PermissionException,
InvalidTokenException,
WrongParameterException,
MissingParameterException,
InvalidQueryException,
DataException,
IndividualAccountChangedNotAllowedException
} }

102
deezer/errors.js Normal file
View 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
}

View file

@ -1,5 +1,6 @@
const got = require('got') const got = require('got')
const {map_artist_album, map_user_track, map_user_artist, map_user_album, map_user_playlist} = require('./utils.js') 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 // Explicit Content Lyrics
const LyricsStatus = { 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 = { module.exports = {
LyricsStatus, LyricsStatus,
PlaylistStatus, PlaylistStatus,
EMPTY_TRACK_OBJ, EMPTY_TRACK_OBJ,
GW, GW
GWAPIError
} }

View file

@ -2,6 +2,7 @@ const got = require('got')
const {CookieJar, Cookie} = require('tough-cookie') const {CookieJar, Cookie} = require('tough-cookie')
const { API } = require('./api.js') const { API } = require('./api.js')
const { GW } = require('./gw.js') const { GW } = require('./gw.js')
const { DeezerError, WrongLicense, WrongGeolocation } = require('./errors.js')
// Number associtation for formats // Number associtation for formats
const TrackFormats = { 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 = { module.exports = {
TrackFormats, TrackFormats,
Deezer, Deezer,
api: {...require('./api.js')}, api: {...require('./api.js')},
gw: {...require('./gw.js')}, gw: {...require('./gw.js')},
utils: {...require('./utils.js')}, utils: {...require('./utils.js')},
errors: { errors: {...require('./errors.js')}
DeezerError,
WrongLicense,
WrongGeolocation
}
} }