Skip to content

Commit

Permalink
chore: simplify errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Aug 4, 2023
1 parent c833635 commit f7ffeab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
18 changes: 18 additions & 0 deletions packages/filecoin-api/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ export class StoreNotFound extends Server.Failure {
}
}

export const EncodeRecordErrorName = /** @type {const} */ (
'EncodeRecordFailed'
)
export class EncodeRecordFailed extends Server.Failure {
/**
* @param {string} message
*/
constructor(message) {
super(message)
}
get reason() {
return this.message
}
get name() {
return EncodeRecordErrorName
}
}

export const DecodeBlockOperationErrorName = /** @type {const} */ (
'DecodeBlockOperationFailed'
)
Expand Down
14 changes: 11 additions & 3 deletions packages/filecoin-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export interface BrokerRecord {

// Errors

export type QueueAddError = QueueOperationError
export type StorePutError = StoreOperationError
export type StoreGetError = StoreOperationError
export type QueueAddError = QueueOperationError | EncodeRecordFailed
export type StorePutError = StoreOperationError | EncodeRecordFailed
export type StoreGetError = StoreOperationError | EncodeRecordFailed | StoreNotFound

export interface QueueOperationError extends Error {
name: 'QueueOperationFailed'
Expand All @@ -81,6 +81,14 @@ export interface StoreOperationError extends Error {
name: 'StoreOperationFailed'
}

export interface StoreNotFound extends Error {
name: 'StoreNotFound'
}

export interface EncodeRecordFailed extends Error {
name: 'EncodeRecordFailed'
}

// Service utils

export interface UcantoServerContext {
Expand Down

0 comments on commit f7ffeab

Please sign in to comment.