Skip to content

Commit

Permalink
feat(httpstatus): support exposing http status of airport code image URL
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-capsule42 committed Jan 20, 2022
1 parent c152152 commit 18edec3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Custom element for the purpose of displaying an avatar image.
| `alt` | `alt` | `String` | "" | provide string for element alt text |
| `ariaVisible` | `ariaVisible` | `Boolean` | null | true value reveals content to screen reader |
| `code` | `code` | `String` | | provide airport code for requested airport image |
| `httpStatus` | `httpStatus` | `String` | null | provides the http status code for the initially declared airport code |
| `img` | `img` | `String` | | provide location or URL for image to be used |
| `tail` | `tail` | `String` | | provide tail logo for requested airline |
| `type` | `type` | `String` | | modifiers for size of avatar (sm \| md) |
15 changes: 13 additions & 2 deletions src/auro-avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import styleCss from "./style-css.js";
* @attr {Boolean} ariaVisible - true value reveals content to screen reader
* @attr {String} alt - provide string for element alt text
* @attr {String} code - provide airport code for requested airport image
* @attr {String} httpStatus - provides the http status code for the initially declared airport code
* @attr {String} img - provide location or URL for image to be used
* @attr {String} tail - provide tail logo for requested airline
* @attr {String} type - modifiers for size of avatar (sm | md)
Expand All @@ -35,6 +36,7 @@ class AuroAvatar extends LitElement {

this.alt = ``;
this.ariaVisible = null;
this.httpStatus = null;
}

// function to define props used within the scope of this component
Expand Down Expand Up @@ -62,6 +64,10 @@ class AuroAvatar extends LitElement {
},
type: {
type: String
},
httpStatus: {
type: String,
reflect: true
}
};
}
Expand Down Expand Up @@ -109,16 +115,21 @@ class AuroAvatar extends LitElement {
* @returns {number} - Returns an http status code.
*/
urlStatus(url) {
let statusCode = null;

try {
const http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return http.status;
statusCode = http.status;
} catch (err) {
// if the http.send() fails for any reason return `404` code
const errorCode = 404;
return errorCode;
statusCode = errorCode;
}

this.httpStatus = statusCode;
return statusCode;
}

/**
Expand Down

0 comments on commit 18edec3

Please sign in to comment.