Skip to content

Commit

Permalink
fixup! change synthetic status codes
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Jul 9, 2024
1 parent e0ef289 commit a7210a4
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,40 +285,40 @@ async function verifyContent (cid, carBytes) {
}

function mapErrorToStatusCode (err) {
// 90x codes for multiaddr parsing errors
// 7xx codes for multiaddr parsing errors
switch (err.code) {
case 'UNSUPPORTED_MULTIADDR_HOST_TYPE':
return 701
case 'UNSUPPORTED_MULTIADDR_PROTO':
return 901
return 702
case 'UNSUPPORTED_MULTIADDR_SCHEME':
return 902
return 703
case 'MULTIADDR_HAS_TOO_MANY_PARTS':
return 903
case 'UNSUPPORTED_MULTIADDR_HOST_TYPE':
return 904
return 704
}

// 92x for content verification errors
// 9xx for content verification errors
if (err instanceof UnsupportedHashError) {
return 921
return 901
} else if (err instanceof HashMismatchError) {
return 922
return 902
} else if (err.code === 'UNEXPECTED_CAR_BLOCK') {
return 923
return 903
} else if (err.code === 'CANNOT_PARSE_CAR_BYTES') {
return 924
return 904
}

// 91x errors for network connection errors
// 8xx errors for network connection errors
// Unfortunately, the Fetch API does not support programmatic detection of various error
// conditions. We have to check the error message text.
if (err.message.includes('dns error')) {
return 911
return 801
} else if (err.message.includes('tcp connect error')) {
return 912
return 802
}

// Fallback code for unknown errors
return 900
return 800
}

async function assertOkResponse (res, errorMsg) {
Expand Down

0 comments on commit a7210a4

Please sign in to comment.