UNPKG

smart-dropzone-react

Version:

🚀 A production-ready React dropzone component with smart defaults, drag & drop reordering, chunked uploads, resume functionality, and comprehensive provider support (Cloudinary, AWS S3, Supabase)

2 lines • 4.18 kB
import {e,b}from'./chunk-74G6TQLM.js';import {a}from'./chunk-5XGN7UAV.js';var i=class a$1 extends Error{constructor(e,t,s,d,u=false){super(t);a(this,"code");a(this,"context");a(this,"userMessage");a(this,"technicalMessage");a(this,"timestamp");a(this,"retryable");this.name="UploadError",this.code=e,this.context=d,this.userMessage=t,this.technicalMessage=s,this.timestamp=new Date,this.retryable=u;}static validationError(e,t){return new a$1("VALIDATION_ERROR",e,`File validation failed: ${e}`,{operation:"validation",fileName:t},false)}static uploadError(e,t,s){return new a$1("UPLOAD_ERROR",e,`Upload failed for file ${s||t}: ${e}`,{operation:"upload",fileId:t,fileName:s},true)}static networkError(e,t){return new a$1("NETWORK_ERROR","Network connection issue. Please check your internet connection and try again.",`Network error: ${e}`,{operation:"network",fileId:t},true)}static providerError(e,t,s){return new a$1("PROVIDER_ERROR","Service temporarily unavailable. Please try again later.",`Provider ${t} error: ${e}`,{operation:"provider",provider:t,fileId:s},true)}static processingError(e,t){return new a$1("PROCESSING_ERROR","File processing failed. Please try a different file.",`Processing error: ${e}`,{operation:"processing",fileId:t},false)}toJSON(){return {code:this.code,userMessage:this.userMessage,technicalMessage:this.technicalMessage,context:this.context,timestamp:this.timestamp.toISOString(),retryable:this.retryable,stack:this.stack}}},n=class n{static getUserMessage(r){if(r instanceof i)return r.userMessage;let e=r.message.toLowerCase();for(let[t,s]of this.errorMap)if(e.includes(t.toLowerCase())||e.includes(t.replace("_"," ").toLowerCase()))return s;return "Something went wrong. Please try again."}static isRetryable(r){if(r instanceof i)return r.retryable;let e=r.message.toLowerCase();return ["network","timeout","connection","server error","temporary","rate limit"].some(s=>e.includes(s))}static getErrorCode(r){if(r instanceof i)return r.code;let e=r.message.toLowerCase();return e.includes("network")||e.includes("connection")?"NETWORK_ERROR":e.includes("timeout")?"TIMEOUT_ERROR":e.includes("validation")?"VALIDATION_ERROR":"UNKNOWN_ERROR"}static logError(r){let e={...r.context,correlationId:r.context.correlationId||this.generateCorrelationId(),sessionId:this.sessionId,userAgent:typeof navigator<"u"?navigator.userAgent:"unknown",timestamp:new Date().toISOString()},t=new i(r.code,r.userMessage,r.technicalMessage,e,r.retryable);this.errorLogs.push(t),this.errorLogs.length>this.maxLogSize&&this.errorLogs.shift(),process.env.NODE_ENV;}static getErrorStats(){let r={total:this.errorLogs.length,byOperation:{},byCode:{},retryableCount:0};return this.errorLogs.forEach(e=>{r.byOperation[e.context.operation]=(r.byOperation[e.context.operation]||0)+1,r.byCode[e.code]=(r.byCode[e.code]||0)+1,e.retryable&&r.retryableCount++;}),r}static clearErrorLogs(){this.errorLogs=[];}static getRecentErrors(r=10){return this.errorLogs.slice(-r)}static shouldRetry(r,e$1){return e$1>=e.MAX_RETRY_ATTEMPTS?false:this.isRetryable(r)}static getRetryDelay(r){return b.RETRY_DELAY*Math.pow(b.RETRY_EXPONENTIAL_BASE,r)}static generateSessionId(){return `session-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}static generateCorrelationId(){return `corr-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}};a(n,"errorMap",new Map([["FILE_TOO_LARGE","File is too large. Please choose a smaller file."],["INVALID_FILE_TYPE","File type not supported. Please choose a different file."],["TOO_MANY_FILES","Too many files selected. Please reduce the number of files."],["NETWORK_TIMEOUT","Upload timed out. Please check your connection and try again."],["QUOTA_EXCEEDED","Storage quota exceeded. Please remove some files and try again."],["FILE_CORRUPTED","File appears to be corrupted. Please try a different file."],["UPLOAD_CANCELLED","Upload was cancelled."],["PROVIDER_UNAVAILABLE","Upload service is temporarily unavailable. Please try again later."]])),a(n,"errorLogs",[]),a(n,"maxLogSize",100),a(n,"sessionId",n.generateSessionId());var g=n;export{i as a,g as b};//# sourceMappingURL=chunk-FB7ESX7E.js.map //# sourceMappingURL=chunk-FB7ESX7E.js.map