Moved errors in separate file

This commit is contained in:
RemixDev 2021-08-02 21:33:58 +02:00
parent 1d1317c135
commit dafee37945
5 changed files with 191 additions and 177 deletions

View file

@ -1,5 +1,6 @@
const got = require('got')
const {_md5, _ecbCrypt, _ecbDecrypt, generateBlowfishKey, decryptChunk} = require('./utils/crypto.js')
const { DownloadCanceled, DownloadEmpty} = require('./errors.js')
const { USER_AGENT_HEADER, pipeline } = require('./utils/index.js')
@ -143,27 +144,11 @@ async function streamTrack(outputStream, track, start=0, downloadObject, listene
}
}
class DownloadEmpty extends Error {
constructor() {
super()
this.name = "DownloadEmpty"
}
}
class DownloadCanceled extends Error {
constructor() {
super()
this.name = "DownloadCanceled"
}
}
module.exports = {
generateStreamPath,
generateStreamURL,
generateCryptedStreamURL,
reverseStreamPath,
reverseStreamURL,
streamTrack,
DownloadEmpty,
DownloadCanceled
streamTrack
}

View file

@ -5,6 +5,7 @@ const { tagID3, tagID3v1, tagFLAC } = require('./tagger.js')
const { USER_AGENT_HEADER, pipeline, shellEscape } = require('./utils/index.js')
const { DEFAULTS, OverwriteOption } = require('./settings.js')
const { generatePath, generateAlbumName, generateArtistName, generateDownloadObjectName } = require('./utils/pathtemplates.js')
const { PreferredBitrateNotFound, TrackNot360, DownloadFailed, ErrorMessages} = require('./errors.js')
const { TrackFormats } = require('deezer-js')
const { WrongLicense, WrongGeolocation } = require('deezer-js').errors
const got = require('got')
@ -558,7 +559,7 @@ class Downloader {
}
}
e.errid += "NoAlternative"
e.message = errorMessages[e.errid]
e.message = ErrorMessages[e.errid]
}
result = {error:{
message: e.message,
@ -690,59 +691,8 @@ class Downloader {
}
}
class DownloadError extends Error {
constructor() {
super()
this.name = "DownloadError"
}
}
const errorMessages = {
notOnDeezer: "Track not available on Deezer!",
notEncoded: "Track not yet encoded!",
notEncodedNoAlternative: "Track not yet encoded and no alternative found!",
wrongBitrate: "Track not found at desired bitrate.",
wrongBitrateNoAlternative: "Track not found at desired bitrate and no alternative found!",
wrongLicense: "Your account can't stream the track at the desired bitrate.",
no360RA: "Track is not available in Reality Audio 360.",
notAvailable: "Track not available on deezer's servers!",
notAvailableNoAlternative: "Track not available on deezer's servers and no alternative found!",
noSpaceLeft: "No space left on target drive, clean up some space for the tracks.",
albumDoesntExists: "Track's album does not exsist, failed to gather info.",
notLoggedIn: "You need to login to download tracks.",
wrongGeolocation: "Your account can't stream the track from your current country."
}
class DownloadFailed extends DownloadError {
constructor(errid, track) {
super()
this.errid = errid
this.message = errorMessages[errid]
this.name = "DownloadFailed"
this.track = track
}
}
class TrackNot360 extends DownloadError {
constructor() {
super()
this.name = "TrackNot360"
}
}
class PreferredBitrateNotFound extends DownloadError {
constructor() {
super()
this.name = "PreferredBitrateNotFound"
}
}
module.exports = {
Downloader,
DownloadError,
DownloadFailed,
downloadImage,
getPreferredBitrate,
TrackNot360,
PreferredBitrateNotFound
getPreferredBitrate
}

182
deemix/errors.js Normal file
View file

@ -0,0 +1,182 @@
class DeemixError extends Error {
constructor(message) {
super(message)
this.name = "DeemixError"
}
}
class GenerationError extends DeemixError {
constructor(link, message) {
super(message)
this.link = link
this.name = "GenerationError"
}
}
class ISRCnotOnDeezer extends GenerationError {
constructor(link) {
super(link, "Track ISRC is not available on deezer")
this.name = "ISRCnotOnDeezer"
this.errid = "ISRCnotOnDeezer"
}
}
class NotYourPrivatePlaylist extends GenerationError {
constructor(link) {
super(link, "You can't download others private playlists.")
this.name = "NotYourPrivatePlaylist"
this.errid = "notYourPrivatePlaylist"
}
}
class TrackNotOnDeezer extends GenerationError {
constructor(link) {
super(link, "Track not found on deezer!")
this.name = "TrackNotOnDeezer"
this.errid = "trackNotOnDeezer"
}
}
class AlbumNotOnDeezer extends GenerationError {
constructor(link) {
super(link, "Album not found on deezer!")
this.name = "AlbumNotOnDeezer"
this.errid = "albumNotOnDeezer"
}
}
class InvalidID extends GenerationError {
constructor(link) {
super(link, "Link ID is invalid!")
this.name = "InvalidID"
this.errid = "invalidID"
}
}
class LinkNotSupported extends GenerationError {
constructor(link) {
super(link, "Link is not supported.")
this.name = "LinkNotSupported"
this.errid = "unsupportedURL"
}
}
class LinkNotRecognized extends GenerationError {
constructor(link) {
super(link, "Link is not recognized.")
this.name = "LinkNotRecognized"
this.errid = "invalidURL"
}
}
class DownloadError extends DeemixError {
constructor() {
super()
this.name = "DownloadError"
}
}
const ErrorMessages = {
notOnDeezer: "Track not available on Deezer!",
notEncoded: "Track not yet encoded!",
notEncodedNoAlternative: "Track not yet encoded and no alternative found!",
wrongBitrate: "Track not found at desired bitrate.",
wrongBitrateNoAlternative: "Track not found at desired bitrate and no alternative found!",
wrongLicense: "Your account can't stream the track at the desired bitrate.",
no360RA: "Track is not available in Reality Audio 360.",
notAvailable: "Track not available on deezer's servers!",
notAvailableNoAlternative: "Track not available on deezer's servers and no alternative found!",
noSpaceLeft: "No space left on target drive, clean up some space for the tracks.",
albumDoesntExists: "Track's album does not exsist, failed to gather info.",
notLoggedIn: "You need to login to download tracks.",
wrongGeolocation: "Your account can't stream the track from your current country."
}
class DownloadFailed extends DownloadError {
constructor(errid, track) {
super()
this.errid = errid
this.message = ErrorMessages[errid]
this.name = "DownloadFailed"
this.track = track
}
}
class TrackNot360 extends DownloadError {
constructor() {
super()
this.name = "TrackNot360"
}
}
class PreferredBitrateNotFound extends DownloadError {
constructor() {
super()
this.name = "PreferredBitrateNotFound"
}
}
class DownloadEmpty extends DeemixError {
constructor() {
super()
this.name = "DownloadEmpty"
}
}
class DownloadCanceled extends DeemixError {
constructor() {
super()
this.name = "DownloadCanceled"
}
}
class TrackError extends DeemixError {
constructor(message) {
super(message);
this.name = "TrackError";
}
}
class MD5NotFound extends TrackError {
constructor(message) {
super(message);
this.name = "MD5NotFound";
}
}
class NoDataToParse extends TrackError {
constructor(message) {
super(message);
this.name = "NoDataToParse";
}
}
class AlbumDoesntExists extends TrackError {
constructor(message) {
super(message);
this.name = "AlbumDoesntExists";
}
}
module.exports = {
DeemixError,
GenerationError,
ISRCnotOnDeezer,
NotYourPrivatePlaylist,
TrackNotOnDeezer,
AlbumNotOnDeezer,
InvalidID,
LinkNotSupported,
LinkNotRecognized,
ErrorMessages,
DownloadError,
DownloadFailed,
TrackNot360,
PreferredBitrateNotFound,
DownloadEmpty,
DownloadCanceled,
TrackError,
MD5NotFound,
NoDataToParse,
AlbumDoesntExists
}

View file

@ -2,6 +2,7 @@ const {
Single,
Collection
} = require('./types/DownloadObjects.js')
const { GenerationError, ISRCnotOnDeezer, InvalidID, NotYourPrivatePlaylist } = require('./errors.js');
const { LyricsStatus } = require('deezer-js').gw
const { map_user_playlist } = require('deezer-js').utils
const { each } = require('async')
@ -310,84 +311,11 @@ async function generateArtistTopItem(dz, id, bitrate){
return generatePlaylistItem(dz, playlistAPI.id, bitrate, playlistAPI, artistTopTracksAPI_gw)
}
class GenerationError extends Error {
constructor(link, message) {
super(message)
this.link = link
this.name = "GenerationError"
}
}
class ISRCnotOnDeezer extends GenerationError {
constructor(link) {
super(link, "Track ISRC is not available on deezer")
this.name = "ISRCnotOnDeezer"
this.errid = "ISRCnotOnDeezer"
}
}
class NotYourPrivatePlaylist extends GenerationError {
constructor(link) {
super(link, "You can't download others private playlists.")
this.name = "NotYourPrivatePlaylist"
this.errid = "notYourPrivatePlaylist"
}
}
class TrackNotOnDeezer extends GenerationError {
constructor(link) {
super(link, "Track not found on deezer!")
this.name = "TrackNotOnDeezer"
this.errid = "trackNotOnDeezer"
}
}
class AlbumNotOnDeezer extends GenerationError {
constructor(link) {
super(link, "Album not found on deezer!")
this.name = "AlbumNotOnDeezer"
this.errid = "albumNotOnDeezer"
}
}
class InvalidID extends GenerationError {
constructor(link) {
super(link, "Link ID is invalid!")
this.name = "InvalidID"
this.errid = "invalidID"
}
}
class LinkNotSupported extends GenerationError {
constructor(link) {
super(link, "Link is not supported.")
this.name = "LinkNotSupported"
this.errid = "unsupportedURL"
}
}
class LinkNotRecognized extends GenerationError {
constructor(link) {
super(link, "Link is not recognized.")
this.name = "LinkNotRecognized"
this.errid = "invalidURL"
}
}
module.exports = {
generateTrackItem,
generateAlbumItem,
generatePlaylistItem,
generateArtistItem,
generateArtistDiscographyItem,
generateArtistTopItem,
GenerationError,
ISRCnotOnDeezer,
NotYourPrivatePlaylist,
TrackNotOnDeezer,
AlbumNotOnDeezer,
InvalidID,
LinkNotSupported,
LinkNotRecognized
generateArtistTopItem
}

View file

@ -8,6 +8,7 @@ const { Date } = require('./Date.js')
const { VARIOUS_ARTISTS } = require('./index.js')
const { changeCase } = require('../utils/index.js')
const { FeaturesOption } = require('../settings.js')
const { TrackError, NoDataToParse, AlbumDoesntExists } = require('../errros.js');
const {
generateReplayGainString,
@ -367,38 +368,6 @@ class Track {
}
}
class TrackError extends Error {
constructor(message) {
super(message);
this.name = "TrackError";
}
}
class MD5NotFound extends TrackError {
constructor(message) {
super(message);
this.name = "MD5NotFound";
}
}
class NoDataToParse extends TrackError {
constructor(message) {
super(message);
this.name = "NoDataToParse";
}
}
class AlbumDoesntExists extends TrackError {
constructor(message) {
super(message);
this.name = "AlbumDoesntExists";
}
}
module.exports = {
Track,
TrackError,
MD5NotFound,
NoDataToParse,
AlbumDoesntExists
Track
}