forked from Joystream/hydra
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydra-cli): hydra-cli deploy features (Joystream#109)
* feat: human readable text from rest response (errors and info messages) affects: @subsquid/hydra-cli * feat: deployment url now shows for deployments:ls command affects: @subsquid/hydra-cli
- Loading branch information
1 parent
a56a0e9
commit 3446596
Showing
6 changed files
with
53 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as fetch from 'node-fetch' | ||
export async function request( | ||
apiUrl: string, | ||
fetchContext: fetch.RequestInit | undefined | ||
): Promise<fetch.Response> { | ||
const response = await fetch.default(apiUrl, fetchContext) | ||
const responseBody = await response.clone().json() | ||
if (response.status === 401) { | ||
throw new Error( | ||
`Bad credentials data. Run hydra-cli login or check your account` | ||
) | ||
} else if (response.status === 400 && responseBody.errors.length === 0) { | ||
throw new Error(responseBody.message) | ||
} else if (response.status === 400 && responseBody.errors.length !== 0) { | ||
let validationErrorString = 'some validation problems\n' | ||
for (const error of responseBody.errors) { | ||
for (const constraint of Object.values(error.constraints)) { | ||
validationErrorString += `${constraint}\n` | ||
} | ||
} | ||
throw new Error(validationErrorString) | ||
} else if (response.status === 200) { | ||
return response | ||
} else { | ||
throw new Error(`Server error`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import { baseUrl } from '../baseUrl' | ||
import fetch from 'node-fetch' | ||
import { request } from '../request' | ||
|
||
export async function me(authToken: string): Promise<string> { | ||
export async function me(authToken: string): Promise<string | undefined> { | ||
const apiUrl = `${baseUrl}/client/me` | ||
const response = await fetch(apiUrl, { | ||
const response = await request(apiUrl, { | ||
headers: { | ||
authorization: `token ${authToken}`, | ||
}, | ||
}) | ||
const responseBody = await response.json() | ||
if (response.status === 200) { | ||
return `Successfully logged as ${responseBody.username}` | ||
} else { | ||
throw new Error( | ||
`Failed, status ${response.status}, message: ${responseBody.message}` | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters