@directus/errors
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -0,1 +1,3 @@ | ||
import { Range } from '@directus/storage'; | ||
interface DirectusError<Extensions = void> extends Error { | ||
@@ -12,2 +14,32 @@ extensions: Extensions; | ||
declare enum ErrorCode { | ||
ContainsNullValues = "CONTAINS_NULL_VALUES", | ||
ContentTooLarge = "CONTENT_TOO_LARGE", | ||
Forbidden = "FORBIDDEN", | ||
IllegalAssetTransformation = "ILLEGAL_ASSET_TRANSFORMATION", | ||
InvalidCredentials = "INVALID_CREDENTIALS", | ||
InvalidForeignKey = "INVALID_FOREIGN_KEY", | ||
InvalidIp = "INVALID_IP", | ||
InvalidOtp = "INVALID_OTP", | ||
InvalidPayload = "INVALID_PAYLOAD", | ||
InvalidProvider = "INVALID_PROVIDER", | ||
InvalidProviderConfig = "INVALID_PROVIDER_CONFIG", | ||
InvalidQuery = "INVALID_QUERY", | ||
InvalidToken = "INVALID_TOKEN", | ||
MethodNotAllowed = "METHOD_NOT_ALLOWED", | ||
NotNullViolation = "NOT_NULL_VIOLATION", | ||
RangeNotSatisfiable = "RANGE_NOT_SATISFIABLE", | ||
RecordNotUnique = "RECORD_NOT_UNIQUE", | ||
RequestsExceeded = "REQUESTS_EXCEEDED", | ||
RouteNotFound = "ROUTE_NOT_FOUND", | ||
ServiceUnavailable = "SERVICE_UNAVAILABLE", | ||
TokenExpired = "TOKEN_EXPIRED", | ||
UnexpectedResponse = "UNEXPECTED_RESPONSE", | ||
UnprocessableContent = "UNPROCESSABLE_CONTENT", | ||
UnsupportedMediaType = "UNSUPPORTED_MEDIA_TYPE", | ||
UserSuspended = "USER_SUSPENDED", | ||
ValueOutOfRange = "VALUE_OUT_OF_RANGE", | ||
ValueTooLong = "VALUE_TOO_LONG" | ||
} | ||
/** | ||
@@ -20,2 +52,118 @@ * Check whether or not a passed thing is a valid Directus error | ||
export { DirectusError, DirectusErrorConstructor, createError, isDirectusError }; | ||
interface ContainsNullValuesErrorExtensions { | ||
collection: string; | ||
field: string; | ||
} | ||
declare const ContainsNullValuesError: DirectusErrorConstructor<ContainsNullValuesErrorExtensions>; | ||
declare const ContentTooLargeError: DirectusErrorConstructor<void>; | ||
declare const ForbiddenError: DirectusErrorConstructor<void>; | ||
interface HitRateLimitErrorExtensions { | ||
limit: number; | ||
reset: Date; | ||
} | ||
declare const HitRateLimitError: DirectusErrorConstructor<HitRateLimitErrorExtensions>; | ||
interface IllegalAssetTransformationErrorExtensions { | ||
invalidTransformations: string[]; | ||
} | ||
declare const IllegalAssetTransformationError: DirectusErrorConstructor<IllegalAssetTransformationErrorExtensions>; | ||
declare const InvalidCredentialsError: DirectusErrorConstructor<void>; | ||
interface InvalidForeignKeyErrorExtensions { | ||
collection: string | null; | ||
field: string | null; | ||
} | ||
declare const InvalidForeignKeyError: DirectusErrorConstructor<InvalidForeignKeyErrorExtensions>; | ||
declare const InvalidIpError: DirectusErrorConstructor<void>; | ||
declare const InvalidOtpError: DirectusErrorConstructor<void>; | ||
interface InvalidPayloadErrorExtensions { | ||
reason: string; | ||
} | ||
declare const InvalidPayloadError: DirectusErrorConstructor<InvalidPayloadErrorExtensions>; | ||
declare const InvalidProviderError: DirectusErrorConstructor<void>; | ||
interface InvalidProviderConfigErrorExtensions { | ||
provider: string; | ||
reason?: string; | ||
} | ||
declare const InvalidProviderConfigError: DirectusErrorConstructor<InvalidProviderConfigErrorExtensions>; | ||
interface InvalidQueryErrorExtensions { | ||
reason: string; | ||
} | ||
declare const InvalidQueryError: DirectusErrorConstructor<InvalidQueryErrorExtensions>; | ||
declare const InvalidTokenError: DirectusErrorConstructor<void>; | ||
interface MethodNotAllowedErrorExtensions { | ||
allowed: string[]; | ||
current: string; | ||
} | ||
declare const MethodNotAllowedError: DirectusErrorConstructor<MethodNotAllowedErrorExtensions>; | ||
interface NotNullViolationErrorExtensions { | ||
collection: string | null; | ||
field: string | null; | ||
} | ||
declare const NotNullViolationError: DirectusErrorConstructor<NotNullViolationErrorExtensions>; | ||
interface RangeNotSatisfiableErrorExtensions { | ||
range: Range; | ||
} | ||
declare const RangeNotSatisfiableError: DirectusErrorConstructor<RangeNotSatisfiableErrorExtensions>; | ||
interface RecordNotUniqueErrorExtensions { | ||
collection: string | null; | ||
field: string | null; | ||
} | ||
declare const RecordNotUniqueError: DirectusErrorConstructor<RecordNotUniqueErrorExtensions>; | ||
interface RouteNotFoundErrorExtensions { | ||
path: string; | ||
} | ||
declare const RouteNotFoundError: DirectusErrorConstructor<RouteNotFoundErrorExtensions>; | ||
interface ServiceUnavailableErrorExtensions { | ||
service: string; | ||
reason: string; | ||
} | ||
declare const ServiceUnavailableError: DirectusErrorConstructor<ServiceUnavailableErrorExtensions>; | ||
declare const TokenExpiredError: DirectusErrorConstructor<void>; | ||
declare const UnexpectedResponseError: DirectusErrorConstructor<void>; | ||
interface UnprocessableContentErrorExtensions { | ||
reason: string; | ||
} | ||
declare const UnprocessableContentError: DirectusErrorConstructor<UnprocessableContentErrorExtensions>; | ||
interface UnsupportedMediaTypeErrorExtensions { | ||
mediaType: string; | ||
where: string; | ||
} | ||
declare const UnsupportedMediaTypeError: DirectusErrorConstructor<UnsupportedMediaTypeErrorExtensions>; | ||
declare const UserSuspendedError: DirectusErrorConstructor<void>; | ||
interface ValueOutOfRangeErrorExtensions { | ||
collection: string | null; | ||
field: string | null; | ||
} | ||
declare const ValueOutOfRangeError: DirectusErrorConstructor<ValueOutOfRangeErrorExtensions>; | ||
interface ValueTooLongErrorExtensions { | ||
collection: string | null; | ||
field: string | null; | ||
} | ||
declare const ValueTooLongError: DirectusErrorConstructor<ValueTooLongErrorExtensions>; | ||
export { ContainsNullValuesError, ContentTooLargeError, DirectusError, DirectusErrorConstructor, ErrorCode, ForbiddenError, HitRateLimitError, IllegalAssetTransformationError, InvalidCredentialsError, InvalidForeignKeyError, InvalidIpError, InvalidOtpError, InvalidPayloadError, InvalidProviderConfigError, InvalidProviderError, InvalidQueryError, InvalidTokenError, MethodNotAllowedError, NotNullViolationError, RangeNotSatisfiableError, RecordNotUniqueError, RouteNotFoundError, ServiceUnavailableError, TokenExpiredError, UnexpectedResponseError, UnprocessableContentError, UnsupportedMediaTypeError, UserSuspendedError, ValueOutOfRangeError, ValueTooLongError, createError, isDirectusError }; |
@@ -19,2 +19,34 @@ // src/create-error.ts | ||
// src/codes.ts | ||
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => { | ||
ErrorCode2["ContainsNullValues"] = "CONTAINS_NULL_VALUES"; | ||
ErrorCode2["ContentTooLarge"] = "CONTENT_TOO_LARGE"; | ||
ErrorCode2["Forbidden"] = "FORBIDDEN"; | ||
ErrorCode2["IllegalAssetTransformation"] = "ILLEGAL_ASSET_TRANSFORMATION"; | ||
ErrorCode2["InvalidCredentials"] = "INVALID_CREDENTIALS"; | ||
ErrorCode2["InvalidForeignKey"] = "INVALID_FOREIGN_KEY"; | ||
ErrorCode2["InvalidIp"] = "INVALID_IP"; | ||
ErrorCode2["InvalidOtp"] = "INVALID_OTP"; | ||
ErrorCode2["InvalidPayload"] = "INVALID_PAYLOAD"; | ||
ErrorCode2["InvalidProvider"] = "INVALID_PROVIDER"; | ||
ErrorCode2["InvalidProviderConfig"] = "INVALID_PROVIDER_CONFIG"; | ||
ErrorCode2["InvalidQuery"] = "INVALID_QUERY"; | ||
ErrorCode2["InvalidToken"] = "INVALID_TOKEN"; | ||
ErrorCode2["MethodNotAllowed"] = "METHOD_NOT_ALLOWED"; | ||
ErrorCode2["NotNullViolation"] = "NOT_NULL_VIOLATION"; | ||
ErrorCode2["RangeNotSatisfiable"] = "RANGE_NOT_SATISFIABLE"; | ||
ErrorCode2["RecordNotUnique"] = "RECORD_NOT_UNIQUE"; | ||
ErrorCode2["RequestsExceeded"] = "REQUESTS_EXCEEDED"; | ||
ErrorCode2["RouteNotFound"] = "ROUTE_NOT_FOUND"; | ||
ErrorCode2["ServiceUnavailable"] = "SERVICE_UNAVAILABLE"; | ||
ErrorCode2["TokenExpired"] = "TOKEN_EXPIRED"; | ||
ErrorCode2["UnexpectedResponse"] = "UNEXPECTED_RESPONSE"; | ||
ErrorCode2["UnprocessableContent"] = "UNPROCESSABLE_CONTENT"; | ||
ErrorCode2["UnsupportedMediaType"] = "UNSUPPORTED_MEDIA_TYPE"; | ||
ErrorCode2["UserSuspended"] = "USER_SUSPENDED"; | ||
ErrorCode2["ValueOutOfRange"] = "VALUE_OUT_OF_RANGE"; | ||
ErrorCode2["ValueTooLong"] = "VALUE_TOO_LONG"; | ||
return ErrorCode2; | ||
})(ErrorCode || {}); | ||
// src/is-directus-error.ts | ||
@@ -28,5 +60,254 @@ var isDirectusError = (err, code) => { | ||
}; | ||
// src/errors/contains-null-values.ts | ||
var messageConstructor = ({ collection, field }) => `Field "${field}" in collection "${collection}" contains null values.`; | ||
var ContainsNullValuesError = createError( | ||
"CONTAINS_NULL_VALUES" /* ContainsNullValues */, | ||
messageConstructor, | ||
400 | ||
); | ||
// src/errors/content-too-large.ts | ||
var ContentTooLargeError = createError("CONTENT_TOO_LARGE" /* ContentTooLarge */, "Uploaded content is too large.", 413); | ||
// src/errors/forbidden.ts | ||
var ForbiddenError = createError("FORBIDDEN" /* Forbidden */, `You don't have permission to access this.`, 403); | ||
// src/errors/hit-rate-limit.ts | ||
import ms from "ms"; | ||
var messageConstructor2 = (extensions) => { | ||
const msBeforeNext = extensions.reset.getTime() - Date.now(); | ||
return `Too many requests, retry after ${ms(msBeforeNext)}.`; | ||
}; | ||
var HitRateLimitError = createError( | ||
"REQUESTS_EXCEEDED" /* RequestsExceeded */, | ||
messageConstructor2, | ||
429 | ||
); | ||
// src/errors/illegal-asset-transformation.ts | ||
var IllegalAssetTransformationError = createError( | ||
"ILLEGAL_ASSET_TRANSFORMATION" /* IllegalAssetTransformation */, | ||
"Illegal asset transformation.", | ||
400 | ||
); | ||
// src/errors/invalid-credentials.ts | ||
var InvalidCredentialsError = createError("INVALID_CREDENTIALS" /* InvalidCredentials */, "Invalid user credentials.", 401); | ||
// src/errors/invalid-foreign-key.ts | ||
var messageConstructor3 = ({ collection, field }) => { | ||
let message = "Invalid foreign key"; | ||
if (field) { | ||
message += ` for field "${field}"`; | ||
} | ||
if (collection) { | ||
message += ` in collection "${collection}"`; | ||
} | ||
message += `.`; | ||
return message; | ||
}; | ||
var InvalidForeignKeyError = createError( | ||
"INVALID_FOREIGN_KEY" /* InvalidForeignKey */, | ||
messageConstructor3, | ||
400 | ||
); | ||
// src/errors/invalid-ip.ts | ||
var InvalidIpError = createError("INVALID_IP" /* InvalidIp */, "Invalid IP address.", 401); | ||
// src/errors/invalid-otp.ts | ||
var InvalidOtpError = createError("INVALID_OTP" /* InvalidOtp */, "Invalid user OTP.", 401); | ||
// src/errors/invalid-payload.ts | ||
var messageConstructor4 = ({ reason }) => `Invalid payload. ${reason}.`; | ||
var InvalidPayloadError = createError( | ||
"INVALID_PAYLOAD" /* InvalidPayload */, | ||
messageConstructor4, | ||
400 | ||
); | ||
// src/errors/invalid-provider.ts | ||
var InvalidProviderError = createError("INVALID_PROVIDER" /* InvalidProvider */, "Invalid provider.", 403); | ||
// src/errors/invalid-provider-config.ts | ||
var InvalidProviderConfigError = createError( | ||
"INVALID_PROVIDER_CONFIG" /* InvalidProviderConfig */, | ||
"Invalid config.", | ||
503 | ||
); | ||
// src/errors/invalid-query.ts | ||
var messageConstructor5 = ({ reason }) => `Invalid query. ${reason}.`; | ||
var InvalidQueryError = createError( | ||
"INVALID_QUERY" /* InvalidQuery */, | ||
messageConstructor5, | ||
400 | ||
); | ||
// src/errors/invalid-token.ts | ||
var InvalidTokenError = createError("INVALID_TOKEN" /* InvalidToken */, "Invalid token.", 403); | ||
// src/errors/method-not-allowed.ts | ||
var messageConstructor6 = (extensions) => `Invalid method "${extensions.current}" used. Should be one of ${extensions.allowed.map((method) => `"${method}"`).join(", ")}.`; | ||
var MethodNotAllowedError = createError( | ||
"METHOD_NOT_ALLOWED" /* MethodNotAllowed */, | ||
messageConstructor6, | ||
405 | ||
); | ||
// src/errors/not-null-violation.ts | ||
var messageConstructor7 = ({ collection, field }) => { | ||
let message = "Value "; | ||
if (field) { | ||
message += `for field "${field}" `; | ||
} | ||
if (collection) { | ||
message += `in collection "${collection}" `; | ||
} | ||
message += `can't be null.`; | ||
return message; | ||
}; | ||
var NotNullViolationError = createError( | ||
"NOT_NULL_VIOLATION" /* NotNullViolation */, | ||
messageConstructor7, | ||
400 | ||
); | ||
// src/errors/range-not-satisfiable.ts | ||
var messageConstructor8 = ({ range }) => { | ||
const rangeString = `"${range.start ?? ""}-${range.end ?? ""}"`; | ||
return `Range ${rangeString} is invalid or the file's size doesn't match the requested range.`; | ||
}; | ||
var RangeNotSatisfiableError = createError( | ||
"RANGE_NOT_SATISFIABLE" /* RangeNotSatisfiable */, | ||
messageConstructor8, | ||
416 | ||
); | ||
// src/errors/record-not-unique.ts | ||
var messageConstructor9 = ({ collection, field }) => { | ||
let message = "Value "; | ||
if (field) { | ||
message += `for field "${field}" `; | ||
} | ||
if (collection) { | ||
message += `in collection "${collection}" `; | ||
} | ||
message += `has to be unique.`; | ||
return message; | ||
}; | ||
var RecordNotUniqueError = createError( | ||
"RECORD_NOT_UNIQUE" /* RecordNotUnique */, | ||
messageConstructor9, | ||
400 | ||
); | ||
// src/errors/route-not-found.ts | ||
var messageConstructor10 = ({ path }) => `Route ${path} doesn't exist.`; | ||
var RouteNotFoundError = createError("ROUTE_NOT_FOUND" /* RouteNotFound */, messageConstructor10, 404); | ||
// src/errors/service-unavailable.ts | ||
var messageConstructor11 = ({ service, reason }) => `Service "${service}" is unavailable. ${reason}.`; | ||
var ServiceUnavailableError = createError( | ||
"SERVICE_UNAVAILABLE" /* ServiceUnavailable */, | ||
messageConstructor11, | ||
503 | ||
); | ||
// src/errors/token-expired.ts | ||
var TokenExpiredError = createError("TOKEN_EXPIRED" /* TokenExpired */, "Token expired.", 401); | ||
// src/errors/unexpected-response.ts | ||
var UnexpectedResponseError = createError( | ||
"UNEXPECTED_RESPONSE" /* UnexpectedResponse */, | ||
"Received an unexpected response.", | ||
503 | ||
); | ||
// src/errors/unprocessable-content.ts | ||
var messageConstructor12 = (extensions) => `Can't process content. ${extensions.reason}.`; | ||
var UnprocessableContentError = createError( | ||
"UNPROCESSABLE_CONTENT" /* UnprocessableContent */, | ||
messageConstructor12, | ||
422 | ||
); | ||
// src/errors/unsupported-media-type.ts | ||
var messageConstructor13 = (extensions) => `Unsupported media type "${extensions.mediaType}" in ${extensions.where}.`; | ||
var UnsupportedMediaTypeError = createError( | ||
"UNSUPPORTED_MEDIA_TYPE" /* UnsupportedMediaType */, | ||
messageConstructor13, | ||
415 | ||
); | ||
// src/errors/user-suspended.ts | ||
var UserSuspendedError = createError("USER_SUSPENDED" /* UserSuspended */, "User suspended.", 401); | ||
// src/errors/value-out-of-range.ts | ||
var messageConstructor14 = ({ collection, field }) => { | ||
let message = "Numeric value "; | ||
if (field) { | ||
message += `for field "${field}" `; | ||
} | ||
if (collection) { | ||
message += `in collection "${collection}" `; | ||
} | ||
message += `is out of range.`; | ||
return message; | ||
}; | ||
var ValueOutOfRangeError = createError( | ||
"VALUE_OUT_OF_RANGE" /* ValueOutOfRange */, | ||
messageConstructor14, | ||
400 | ||
); | ||
// src/errors/value-too-long.ts | ||
var messageConstructor15 = ({ collection, field }) => { | ||
let message = "Value "; | ||
if (field) { | ||
message += `for field "${field}" `; | ||
} | ||
if (collection) { | ||
message += `in collection "${collection}" `; | ||
} | ||
message += `is too long.`; | ||
return message; | ||
}; | ||
var ValueTooLongError = createError( | ||
"VALUE_TOO_LONG" /* ValueTooLong */, | ||
messageConstructor15, | ||
400 | ||
); | ||
export { | ||
ContainsNullValuesError, | ||
ContentTooLargeError, | ||
ErrorCode, | ||
ForbiddenError, | ||
HitRateLimitError, | ||
IllegalAssetTransformationError, | ||
InvalidCredentialsError, | ||
InvalidForeignKeyError, | ||
InvalidIpError, | ||
InvalidOtpError, | ||
InvalidPayloadError, | ||
InvalidProviderConfigError, | ||
InvalidProviderError, | ||
InvalidQueryError, | ||
InvalidTokenError, | ||
MethodNotAllowedError, | ||
NotNullViolationError, | ||
RangeNotSatisfiableError, | ||
RecordNotUniqueError, | ||
RouteNotFoundError, | ||
ServiceUnavailableError, | ||
TokenExpiredError, | ||
UnexpectedResponseError, | ||
UnprocessableContentError, | ||
UnsupportedMediaTypeError, | ||
UserSuspendedError, | ||
ValueOutOfRangeError, | ||
ValueTooLongError, | ||
createError, | ||
isDirectusError | ||
}; |
{ | ||
"name": "@directus/errors", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Create consistent error objects around the codebase", | ||
@@ -23,2 +23,6 @@ "repository": { | ||
], | ||
"dependencies": { | ||
"ms": "2.1.3", | ||
"@directus/storage": "10.0.6" | ||
}, | ||
"devDependencies": { | ||
@@ -28,8 +32,7 @@ "@types/ms": "0.7.31", | ||
"@vitest/coverage-c8": "0.31.1", | ||
"tsup": "6.7.0", | ||
"typescript": "5.0.4", | ||
"tsup": "7.2.0", | ||
"typescript": "5.2.2", | ||
"vitest": "0.31.1", | ||
"@directus/random": "0.2.2", | ||
"@directus/tsconfig": "1.0.0", | ||
"@directus/types": "10.1.3" | ||
"@directus/random": "0.2.3", | ||
"@directus/tsconfig": "1.0.1" | ||
}, | ||
@@ -36,0 +39,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20284
8
420
2
1
+ Added@directus/storage@10.0.6
+ Addedms@2.1.3
+ Added@directus/storage@10.0.6(transitive)
+ Addedms@2.1.3(transitive)