Return JSON empty array when not found, and handle null arrays
This commit is contained in:
parent
d0adb9c4db
commit
af7f666eff
2 changed files with 3 additions and 2 deletions
|
@ -218,7 +218,7 @@ func (s *SQLStore) GetAllBlocks() ([]model.Block, error) {
|
||||||
func blocksFromRows(rows *sql.Rows) ([]model.Block, error) {
|
func blocksFromRows(rows *sql.Rows) ([]model.Block, error) {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var results []model.Block
|
var results = []model.Block{}
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var block model.Block
|
var block model.Block
|
||||||
|
|
|
@ -28,7 +28,8 @@ class OctoClient {
|
||||||
private async getJson(response: Response, defaultValue: any = {}): Promise<any> {
|
private async getJson(response: Response, defaultValue: any = {}): Promise<any> {
|
||||||
// The server may return null or malformed json
|
// The server may return null or malformed json
|
||||||
try {
|
try {
|
||||||
return await response.json()
|
const value = await response.json()
|
||||||
|
return value || defaultValue
|
||||||
} catch {
|
} catch {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue