source: trip-planner-front/node_modules/npm-registry-fetch/errors.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1'use strict'
2
3const url = require('url')
4
5function packageName (href) {
6 try {
7 let basePath = new url.URL(href).pathname.substr(1)
8 if (!basePath.match(/^-/)) {
9 basePath = basePath.split('/')
10 var index = basePath.indexOf('_rewrite')
11 if (index === -1)
12 index = basePath.length - 1
13 else
14 index++
15 return decodeURIComponent(basePath[index])
16 }
17 } catch (_) {
18 // this is ok
19 }
20}
21
22class HttpErrorBase extends Error {
23 constructor (method, res, body, spec) {
24 super()
25 this.name = this.constructor.name
26 this.headers = res.headers.raw()
27 this.statusCode = res.status
28 this.code = `E${res.status}`
29 this.method = method
30 this.uri = res.url
31 this.body = body
32 this.pkgid = spec ? spec.toString() : packageName(res.url)
33 }
34}
35module.exports.HttpErrorBase = HttpErrorBase
36
37class HttpErrorGeneral extends HttpErrorBase {
38 constructor (method, res, body, spec) {
39 super(method, res, body, spec)
40 this.message = `${res.status} ${res.statusText} - ${
41 this.method.toUpperCase()
42 } ${
43 this.spec || this.uri
44 }${
45 (body && body.error) ? ' - ' + body.error : ''
46 }`
47 Error.captureStackTrace(this, HttpErrorGeneral)
48 }
49}
50module.exports.HttpErrorGeneral = HttpErrorGeneral
51
52class HttpErrorAuthOTP extends HttpErrorBase {
53 constructor (method, res, body, spec) {
54 super(method, res, body, spec)
55 this.message = 'OTP required for authentication'
56 this.code = 'EOTP'
57 Error.captureStackTrace(this, HttpErrorAuthOTP)
58 }
59}
60module.exports.HttpErrorAuthOTP = HttpErrorAuthOTP
61
62class HttpErrorAuthIPAddress extends HttpErrorBase {
63 constructor (method, res, body, spec) {
64 super(method, res, body, spec)
65 this.message = 'Login is not allowed from your IP address'
66 this.code = 'EAUTHIP'
67 Error.captureStackTrace(this, HttpErrorAuthIPAddress)
68 }
69}
70module.exports.HttpErrorAuthIPAddress = HttpErrorAuthIPAddress
71
72class HttpErrorAuthUnknown extends HttpErrorBase {
73 constructor (method, res, body, spec) {
74 super(method, res, body, spec)
75 this.message = 'Unable to authenticate, need: ' + res.headers.get('www-authenticate')
76 Error.captureStackTrace(this, HttpErrorAuthUnknown)
77 }
78}
79module.exports.HttpErrorAuthUnknown = HttpErrorAuthUnknown
Note: See TracBrowser for help on using the repository browser.