1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-29 07:54:19 +00:00
pds-2021-g2-nest/nest_frontend/objects/Errors.js

113 lines
2 KiB
JavaScript
Raw Normal View History

/**
* Error thrown when a function is not implemented in the current class/instance.
*/
2021-05-24 03:02:07 +00:00
export class NotImplementedError {
name
constructor(name) {
this.name = name
}
}
/**
* An error in the N.E.S.T. frontend-backend communication.
*/
2021-05-24 03:02:07 +00:00
export class BackendCommunicationError {
}
/**
* Error thrown when trying to access a backend view which doesn't exist or isn't allowed in the used hook.
*/
2021-05-24 03:02:07 +00:00
export class ViewNotAllowedError extends BackendCommunicationError {
view
constructor(view) {
super()
this.view = view
}
}
/**
* Error thrown when trying to access a backend view when outside a {@link ContextServer}.
*/
2021-05-24 03:02:07 +00:00
export class ServerNotConfiguredError extends BackendCommunicationError {
}
/**
* Error thrown when trying to access a backend view while another access is ongoing.
*
* This is not allowed due to potential race conditions.
*/
2021-05-24 03:02:07 +00:00
export class FetchAlreadyRunningError extends BackendCommunicationError {
}
/**
* Abstract class for {@link DecodeError} and {@link ResultError}.
*/
2021-05-24 03:02:07 +00:00
export class FetchError extends BackendCommunicationError {
status
statusText
constructor(status, statusText) {
super()
this.status = status
this.statusText = statusText
}
}
/**
* Error thrown when the frontend can't parse the data received from the backend.
*/
2021-05-24 03:02:07 +00:00
export class DecodeError extends FetchError {
error
constructor(status, statusText, error) {
super(status, statusText)
this.error = error
}
}
/**
* Error thrown when the backend returns a falsy `"result"` value.
*/
2021-05-24 03:02:07 +00:00
export class ResultError extends FetchError {
status
statusText
data
constructor(status, statusText, data) {
super(status, statusText)
this.data = data
}
getMsg() {
return this.data.msg
}
getCode() {
return this.data.code
}
}
2021-05-24 03:02:07 +00:00
export class SerializationError {
invalidString
constructor(invalidString) {
this.invalidString = invalidString
}
}