Skip to content

Commit

Permalink
feat: update common package
Browse files Browse the repository at this point in the history
  • Loading branch information
yknl committed Aug 11, 2020
1 parent c27d948 commit 2132b08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 64 deletions.
19 changes: 19 additions & 0 deletions packages/common/src/constants.ts
@@ -0,0 +1,19 @@
enum ChainID {
Testnet = 0x80000000,
Mainnet = 0x00000001,
}

enum TransactionVersion {
Mainnet = 0x00,
Testnet = 0x80,
}

export {
ChainID,
TransactionVersion,
};

/**
* @ignore
*/
export const BLOCKSTACK_DEFAULT_GAIA_HUB_URL = 'https://hub.blockstack.org'
3 changes: 2 additions & 1 deletion packages/common/src/index.ts
Expand Up @@ -2,4 +2,5 @@ export * from './config';
export * from './errors';
export * from './fetchUtil';
export * from './logger';
export * from './utils';
export * from './utils';
export * from './constants';
63 changes: 0 additions & 63 deletions packages/common/src/utils.ts
@@ -1,15 +1,4 @@
import { Logger } from './logger'
import {
BadPathError,
ConflictError,
DoesNotExist,
GaiaHubErrorResponse,
NotEnoughProofError,
PayloadTooLargeError,
ValidationError,
PreconditionFailedError
} from './errors'


/**
* @ignore
Expand Down Expand Up @@ -349,55 +338,3 @@ export function getGlobalObjects<K extends Extract<keyof Window, string>>(
}
return result
}

async function getGaiaErrorResponse(response: Response): Promise<GaiaHubErrorResponse> {
let responseMsg = ''
let responseJson: any | undefined
try {
responseMsg = await response.text()
try {
responseJson = JSON.parse(responseMsg)
} catch (error) {
// Use text instead
}
} catch (error) {
Logger.debug(`Error getting bad http response text: ${error}`)
}
const status = response.status
const statusText = response.statusText
const body = responseJson || responseMsg
return { status, statusText, body }
}

/**
* Returns a BlockstackError correlating to the given HTTP response,
* with the provided errorMsg. Throws if the HTTP response is 'ok'.
*/
// export async function getBlockstackErrorFromResponse(
// response: Response,
// errorMsg: string,
// hubConfig: import('./storage/hub').GaiaHubConfig | null
// ): Promise<Error> {
// if (response.ok) {
// throw new Error('Cannot get a BlockstackError from a valid response.')
// }
// const gaiaResponse = await getGaiaErrorResponse(response)
// if (gaiaResponse.status === 401) {
// return new ValidationError(errorMsg, gaiaResponse)
// } else if (gaiaResponse.status === 402) {
// return new NotEnoughProofError(errorMsg, gaiaResponse)
// } else if (gaiaResponse.status === 403) {
// return new BadPathError(errorMsg, gaiaResponse)
// } else if (gaiaResponse.status === 404) {
// throw new DoesNotExist(errorMsg, gaiaResponse)
// } else if (gaiaResponse.status === 409) {
// return new ConflictError(errorMsg, gaiaResponse)
// } else if (gaiaResponse.status === 412) {
// return new PreconditionFailedError(errorMsg, gaiaResponse)
// } else if (gaiaResponse.status === 413) {
// const maxBytes = megabytesToBytes(hubConfig?.max_file_upload_size_megabytes)
// return new PayloadTooLargeError(errorMsg, gaiaResponse, maxBytes)
// } else {
// return new Error(errorMsg)
// }
// }

0 comments on commit 2132b08

Please sign in to comment.